delete files in multiple subfolders with batchHow can I pass arguments to a batch file?Batch file to delete files older than N daysSplit long commands in multiple lines through Windows batch fileWindows batch files: .bat vs .cmd?How to run multiple .BAT files within a .BAT fileBatch file. Delete all files and folders in a directoryHow to “comment-out” (add comment) in a batch/cmd?Batch file to delete subfolders in directory if all files is older than 3 daysWindows 7 batch file Copy all files from a folder structure to one folderbatch to delete subfolders of all subfolders

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Implement the Thanos sorting algorithm

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

How can I replace every global instance of "x[2]" with "x_2"

What to do with wrong results in talks?

Minimal reference content

Personal Teleportation as a Weapon

How does it work when somebody invests in my business?

How does residential electricity work?

Increase performance creating Mandelbrot set in python

How do I rename a LINUX host without needing to reboot for the rename to take effect?

Print name if parameter passed to function

What defines a dissertation?

Hide Select Output from T-SQL

Can a monster with multiattack use this ability if they are missing a limb?

Bash method for viewing beginning and end of file

Why does John Bercow say “unlock” after reading out the results of a vote?

Can I use my Chinese passport to enter China after I acquired another citizenship?

Is there a problem with hiding "forgot password" until it's needed?

when is out of tune ok?

Your magic is very sketchy

Lay out the Carpet

Is a roofing delivery truck likely to crack my driveway slab?

What is the opposite of 'gravitas'?



delete files in multiple subfolders with batch


How can I pass arguments to a batch file?Batch file to delete files older than N daysSplit long commands in multiple lines through Windows batch fileWindows batch files: .bat vs .cmd?How to run multiple .BAT files within a .BAT fileBatch file. Delete all files and folders in a directoryHow to “comment-out” (add comment) in a batch/cmd?Batch file to delete subfolders in directory if all files is older than 3 daysWindows 7 batch file Copy all files from a folder structure to one folderbatch to delete subfolders of all subfolders













-3















I have a directory that looks like this




"C:salesclient1file1".




The client1 folder it's not static and can vary from client1 to client100 and each file inside the client folder can vary from file1 to file8.



I want to delete 4 speciefic files (eg file1, file3, file6 and file8) in every client folder, based on a mask (/m file1*) older than 7 days (d-7) using a batch.



So far every solution i have tried works for a specified directory



Thank you










share|improve this question



















  • 2





    Stack Overflow isn't a script writing service, what have you tried so far? edit your question to conntain your efforts in a Minimal, Complete, and Verifiable example.

    – LotPings
    Mar 7 at 12:09











  • Yes, if you noticed i said that every solution i tried worked only for a given path, my problem is changing subfolder without having to add a line for every folder.

    – dammyware
    Mar 7 at 13:52







  • 1





    This site expects you to provide the code you've tried which is causing the issue you're reporting. If you've tried more than one solution, it is important that you post those attempts and explain exactly what happens, which differs from yuor expectaitions, when you run each.

    – Compo
    Mar 7 at 14:06
















-3















I have a directory that looks like this




"C:salesclient1file1".




The client1 folder it's not static and can vary from client1 to client100 and each file inside the client folder can vary from file1 to file8.



I want to delete 4 speciefic files (eg file1, file3, file6 and file8) in every client folder, based on a mask (/m file1*) older than 7 days (d-7) using a batch.



So far every solution i have tried works for a specified directory



Thank you










share|improve this question



















  • 2





    Stack Overflow isn't a script writing service, what have you tried so far? edit your question to conntain your efforts in a Minimal, Complete, and Verifiable example.

    – LotPings
    Mar 7 at 12:09











  • Yes, if you noticed i said that every solution i tried worked only for a given path, my problem is changing subfolder without having to add a line for every folder.

    – dammyware
    Mar 7 at 13:52







  • 1





    This site expects you to provide the code you've tried which is causing the issue you're reporting. If you've tried more than one solution, it is important that you post those attempts and explain exactly what happens, which differs from yuor expectaitions, when you run each.

    – Compo
    Mar 7 at 14:06














-3












-3








-3








I have a directory that looks like this




"C:salesclient1file1".




The client1 folder it's not static and can vary from client1 to client100 and each file inside the client folder can vary from file1 to file8.



I want to delete 4 speciefic files (eg file1, file3, file6 and file8) in every client folder, based on a mask (/m file1*) older than 7 days (d-7) using a batch.



So far every solution i have tried works for a specified directory



Thank you










share|improve this question
















I have a directory that looks like this




"C:salesclient1file1".




The client1 folder it's not static and can vary from client1 to client100 and each file inside the client folder can vary from file1 to file8.



I want to delete 4 speciefic files (eg file1, file3, file6 and file8) in every client folder, based on a mask (/m file1*) older than 7 days (d-7) using a batch.



So far every solution i have tried works for a specified directory



Thank you







batch-file cmd forfiles






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 14:19









LotPings

19.9k61633




19.9k61633










asked Mar 7 at 11:35









dammywaredammyware

27




27







  • 2





    Stack Overflow isn't a script writing service, what have you tried so far? edit your question to conntain your efforts in a Minimal, Complete, and Verifiable example.

    – LotPings
    Mar 7 at 12:09











  • Yes, if you noticed i said that every solution i tried worked only for a given path, my problem is changing subfolder without having to add a line for every folder.

    – dammyware
    Mar 7 at 13:52







  • 1





    This site expects you to provide the code you've tried which is causing the issue you're reporting. If you've tried more than one solution, it is important that you post those attempts and explain exactly what happens, which differs from yuor expectaitions, when you run each.

    – Compo
    Mar 7 at 14:06













  • 2





    Stack Overflow isn't a script writing service, what have you tried so far? edit your question to conntain your efforts in a Minimal, Complete, and Verifiable example.

    – LotPings
    Mar 7 at 12:09











  • Yes, if you noticed i said that every solution i tried worked only for a given path, my problem is changing subfolder without having to add a line for every folder.

    – dammyware
    Mar 7 at 13:52







  • 1





    This site expects you to provide the code you've tried which is causing the issue you're reporting. If you've tried more than one solution, it is important that you post those attempts and explain exactly what happens, which differs from yuor expectaitions, when you run each.

    – Compo
    Mar 7 at 14:06








2




2





Stack Overflow isn't a script writing service, what have you tried so far? edit your question to conntain your efforts in a Minimal, Complete, and Verifiable example.

– LotPings
Mar 7 at 12:09





Stack Overflow isn't a script writing service, what have you tried so far? edit your question to conntain your efforts in a Minimal, Complete, and Verifiable example.

– LotPings
Mar 7 at 12:09













Yes, if you noticed i said that every solution i tried worked only for a given path, my problem is changing subfolder without having to add a line for every folder.

– dammyware
Mar 7 at 13:52






Yes, if you noticed i said that every solution i tried worked only for a given path, my problem is changing subfolder without having to add a line for every folder.

– dammyware
Mar 7 at 13:52





1




1





This site expects you to provide the code you've tried which is causing the issue you're reporting. If you've tried more than one solution, it is important that you post those attempts and explain exactly what happens, which differs from yuor expectaitions, when you run each.

– Compo
Mar 7 at 14:06






This site expects you to provide the code you've tried which is causing the issue you're reporting. If you've tried more than one solution, it is important that you post those attempts and explain exactly what happens, which differs from yuor expectaitions, when you run each.

– Compo
Mar 7 at 14:06













1 Answer
1






active

oldest

votes


















1














As your mask is a file and the @path will contain the file name,



you'll have to cd to the folder with .. appended to it @path..



So try:



 forfiles /P C:Sales /S /M file1* /D -7 /C "cmd.exe /c @cd /D @path..&del file1 file3 file6 file8"


This command will also find file1 matching the criteria directly in C:Sales



A more consize solution using PowerShell



Get-ChildItem "C:SalesClient*file1" -File | 
Where LastWriteTime -lt (Get-Date).Date.AddDays(-7)|
ForEach-Object
PushD $_.Directory
Remove-Object file[1368]
PopD






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    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%2fstackoverflow.com%2fquestions%2f55042842%2fdelete-files-in-multiple-subfolders-with-batch%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














    As your mask is a file and the @path will contain the file name,



    you'll have to cd to the folder with .. appended to it @path..



    So try:



     forfiles /P C:Sales /S /M file1* /D -7 /C "cmd.exe /c @cd /D @path..&del file1 file3 file6 file8"


    This command will also find file1 matching the criteria directly in C:Sales



    A more consize solution using PowerShell



    Get-ChildItem "C:SalesClient*file1" -File | 
    Where LastWriteTime -lt (Get-Date).Date.AddDays(-7)|
    ForEach-Object
    PushD $_.Directory
    Remove-Object file[1368]
    PopD






    share|improve this answer





























      1














      As your mask is a file and the @path will contain the file name,



      you'll have to cd to the folder with .. appended to it @path..



      So try:



       forfiles /P C:Sales /S /M file1* /D -7 /C "cmd.exe /c @cd /D @path..&del file1 file3 file6 file8"


      This command will also find file1 matching the criteria directly in C:Sales



      A more consize solution using PowerShell



      Get-ChildItem "C:SalesClient*file1" -File | 
      Where LastWriteTime -lt (Get-Date).Date.AddDays(-7)|
      ForEach-Object
      PushD $_.Directory
      Remove-Object file[1368]
      PopD






      share|improve this answer



























        1












        1








        1







        As your mask is a file and the @path will contain the file name,



        you'll have to cd to the folder with .. appended to it @path..



        So try:



         forfiles /P C:Sales /S /M file1* /D -7 /C "cmd.exe /c @cd /D @path..&del file1 file3 file6 file8"


        This command will also find file1 matching the criteria directly in C:Sales



        A more consize solution using PowerShell



        Get-ChildItem "C:SalesClient*file1" -File | 
        Where LastWriteTime -lt (Get-Date).Date.AddDays(-7)|
        ForEach-Object
        PushD $_.Directory
        Remove-Object file[1368]
        PopD






        share|improve this answer















        As your mask is a file and the @path will contain the file name,



        you'll have to cd to the folder with .. appended to it @path..



        So try:



         forfiles /P C:Sales /S /M file1* /D -7 /C "cmd.exe /c @cd /D @path..&del file1 file3 file6 file8"


        This command will also find file1 matching the criteria directly in C:Sales



        A more consize solution using PowerShell



        Get-ChildItem "C:SalesClient*file1" -File | 
        Where LastWriteTime -lt (Get-Date).Date.AddDays(-7)|
        ForEach-Object
        PushD $_.Directory
        Remove-Object file[1368]
        PopD







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 7 at 15:04

























        answered Mar 7 at 12:40









        LotPingsLotPings

        19.9k61633




        19.9k61633





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • 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%2fstackoverflow.com%2fquestions%2f55042842%2fdelete-files-in-multiple-subfolders-with-batch%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

            AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

            Алба-Юлія

            Захаров Федір Захарович