Batch file to delete/remove folders old of xx days












0















I need a batch file to delete folders old of 1 day.



The folders contains inside files that will be removed together with the folders



I tryed 3 different code but do not remove the old folders.



Path where are located folders to delete (path have space):



D:Programmi Installati


Example folder names (start with log_)



log_1
log_10-12-2019
log_2008-10000
log_222222211111


Days old: 1



:: Code 1

@echo off
setlocal

set target="D:Programmi Installati"
set days=1

for /f "usebackq delims=" %%G in (
'forfiles /p "%target%" /c "cmd /c if /i @isdir == true echo @path" /d -%days% 2^>nul'
) do rd /s /q "%%~G"

pause
endlocal & exit /b


:: Code 2

forfiles /p "D:Programmi Installati" /d -1 /c "cmd /c if @isdir==true rd /s /q @path"



:: Code 3

FORFILES /P "D:Programmi Installati" /S /C "cmd /c IF @isdir == TRUE rmdir /S @path /Q" -D -1


I'm interested a fix of code already indicate or a new code that works.










share|improve this question























  • There should be some already answered questions of the same type at superuser.com/search?q=batch+delete+files+days

    – Florian Straub
    Jan 17 at 16:00











  • After some days i find a solution that works i add the solution here

    – placidomaio
    Jan 17 at 19:29
















0















I need a batch file to delete folders old of 1 day.



The folders contains inside files that will be removed together with the folders



I tryed 3 different code but do not remove the old folders.



Path where are located folders to delete (path have space):



D:Programmi Installati


Example folder names (start with log_)



log_1
log_10-12-2019
log_2008-10000
log_222222211111


Days old: 1



:: Code 1

@echo off
setlocal

set target="D:Programmi Installati"
set days=1

for /f "usebackq delims=" %%G in (
'forfiles /p "%target%" /c "cmd /c if /i @isdir == true echo @path" /d -%days% 2^>nul'
) do rd /s /q "%%~G"

pause
endlocal & exit /b


:: Code 2

forfiles /p "D:Programmi Installati" /d -1 /c "cmd /c if @isdir==true rd /s /q @path"



:: Code 3

FORFILES /P "D:Programmi Installati" /S /C "cmd /c IF @isdir == TRUE rmdir /S @path /Q" -D -1


I'm interested a fix of code already indicate or a new code that works.










share|improve this question























  • There should be some already answered questions of the same type at superuser.com/search?q=batch+delete+files+days

    – Florian Straub
    Jan 17 at 16:00











  • After some days i find a solution that works i add the solution here

    – placidomaio
    Jan 17 at 19:29














0












0








0


1






I need a batch file to delete folders old of 1 day.



The folders contains inside files that will be removed together with the folders



I tryed 3 different code but do not remove the old folders.



Path where are located folders to delete (path have space):



D:Programmi Installati


Example folder names (start with log_)



log_1
log_10-12-2019
log_2008-10000
log_222222211111


Days old: 1



:: Code 1

@echo off
setlocal

set target="D:Programmi Installati"
set days=1

for /f "usebackq delims=" %%G in (
'forfiles /p "%target%" /c "cmd /c if /i @isdir == true echo @path" /d -%days% 2^>nul'
) do rd /s /q "%%~G"

pause
endlocal & exit /b


:: Code 2

forfiles /p "D:Programmi Installati" /d -1 /c "cmd /c if @isdir==true rd /s /q @path"



:: Code 3

FORFILES /P "D:Programmi Installati" /S /C "cmd /c IF @isdir == TRUE rmdir /S @path /Q" -D -1


I'm interested a fix of code already indicate or a new code that works.










share|improve this question














I need a batch file to delete folders old of 1 day.



The folders contains inside files that will be removed together with the folders



I tryed 3 different code but do not remove the old folders.



Path where are located folders to delete (path have space):



D:Programmi Installati


Example folder names (start with log_)



log_1
log_10-12-2019
log_2008-10000
log_222222211111


Days old: 1



:: Code 1

@echo off
setlocal

set target="D:Programmi Installati"
set days=1

for /f "usebackq delims=" %%G in (
'forfiles /p "%target%" /c "cmd /c if /i @isdir == true echo @path" /d -%days% 2^>nul'
) do rd /s /q "%%~G"

pause
endlocal & exit /b


:: Code 2

forfiles /p "D:Programmi Installati" /d -1 /c "cmd /c if @isdir==true rd /s /q @path"



:: Code 3

FORFILES /P "D:Programmi Installati" /S /C "cmd /c IF @isdir == TRUE rmdir /S @path /Q" -D -1


I'm interested a fix of code already indicate or a new code that works.







windows batch






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 13 at 23:03









placidomaioplacidomaio

165




165













  • There should be some already answered questions of the same type at superuser.com/search?q=batch+delete+files+days

    – Florian Straub
    Jan 17 at 16:00











  • After some days i find a solution that works i add the solution here

    – placidomaio
    Jan 17 at 19:29



















  • There should be some already answered questions of the same type at superuser.com/search?q=batch+delete+files+days

    – Florian Straub
    Jan 17 at 16:00











  • After some days i find a solution that works i add the solution here

    – placidomaio
    Jan 17 at 19:29

















There should be some already answered questions of the same type at superuser.com/search?q=batch+delete+files+days

– Florian Straub
Jan 17 at 16:00





There should be some already answered questions of the same type at superuser.com/search?q=batch+delete+files+days

– Florian Straub
Jan 17 at 16:00













After some days i find a solution that works i add the solution here

– placidomaio
Jan 17 at 19:29





After some days i find a solution that works i add the solution here

– placidomaio
Jan 17 at 19:29










1 Answer
1






active

oldest

votes


















1














This is the solution that works



@echo off
forfiles /P "D:Programmi Installati" /M "log_*" /D -1 /C "cmd /c if @isdir==TRUE echo rd /s /q @path"


This code remove only folder with "log_" after 1 day.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1393918%2fbatch-file-to-delete-remove-folders-old-of-xx-days%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    This is the solution that works



    @echo off
    forfiles /P "D:Programmi Installati" /M "log_*" /D -1 /C "cmd /c if @isdir==TRUE echo rd /s /q @path"


    This code remove only folder with "log_" after 1 day.






    share|improve this answer




























      1














      This is the solution that works



      @echo off
      forfiles /P "D:Programmi Installati" /M "log_*" /D -1 /C "cmd /c if @isdir==TRUE echo rd /s /q @path"


      This code remove only folder with "log_" after 1 day.






      share|improve this answer


























        1












        1








        1







        This is the solution that works



        @echo off
        forfiles /P "D:Programmi Installati" /M "log_*" /D -1 /C "cmd /c if @isdir==TRUE echo rd /s /q @path"


        This code remove only folder with "log_" after 1 day.






        share|improve this answer













        This is the solution that works



        @echo off
        forfiles /P "D:Programmi Installati" /M "log_*" /D -1 /C "cmd /c if @isdir==TRUE echo rd /s /q @path"


        This code remove only folder with "log_" after 1 day.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 17 at 19:30









        placidomaioplacidomaio

        165




        165






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1393918%2fbatch-file-to-delete-remove-folders-old-of-xx-days%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Сан-Квентин

            8-я гвардейская общевойсковая армия

            Алькесар