Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch File Help  (Read 3373 times)

0 Members and 1 Guest are viewing this topic.

Rodriguez

    Topic Starter


    Starter

    • Experience: Experienced
    • OS: Other
    Batch File Help
    « on: February 21, 2017, 04:35:22 AM »
    Hi all, I was hop(e)ing for some assistance with a batch script I have been writing.

    I have to delete a bunch of files from thousands of subfolders, and I'm having some trouble figuring out the right syntax for it.

    So far I have this:

    @echo off
     ;;;remove all temporary subfolders that are older than today
     ;;;del isn't the right command for folders of course
     del "Z:\projects\*_backup\"
     del "D:\localdatatemp\*_backup\"
     
     ;;;remove all temporary files that are older than 3 months ago
     del /S /Q "Z:\projects\*.00??.rvt"
     
     ;;;remove all temporary files that are older than 6 months ago
     del /S /Q "D:\localdatatemp\*.rvt"

     

    I am using Windows 10 x64 with system date format as DDMMYYYY, which seems to be important for filtering filedates, but I'm not sure how to go about it as the only example I found was for US filedates.

    If I have posted in the wrong section, please let me know.
    I would be grateful for any help, thankyou.


    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Batch File Help
    « Reply #1 on: February 21, 2017, 12:26:34 PM »
    Look at the FORFILES command.  It has the date option you need.

    Rodriguez

      Topic Starter


      Starter

      • Experience: Experienced
      • OS: Other
      Re: Batch File Help
      « Reply #2 on: February 27, 2017, 04:17:36 AM »
      Hi Squashman,

      Thankyou for the reply — the FORFILES is very handy

      FORFILES /S /D -7 /C "cmd /c del Z:\projects\@fname*.00??.rvt"

      works very well, but it doesn't seem to have a feature to remove folders ?

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: Batch File Help
      « Reply #3 on: February 28, 2017, 08:24:36 AM »
      Hi Squashman,

      Thankyou for the reply — the FORFILES is very handy

      FORFILES /S /D -7 /C "cmd /c del Z:\projects\@fname*.00??.rvt"

      works very well, but it doesn't seem to have a feature to remove folders ?
      No more then any other command that was not designed to remove folders or files.  FORFILES just helps you chose the files you need to process.

      I bet if you Goolge searched bactch file remove directory, this would be the first link it finds.
      https://technet.microsoft.com/en-us/library/bb490990.aspx

      Rodriguez

        Topic Starter


        Starter

        • Experience: Experienced
        • OS: Other
        Re: Batch File Help
        « Reply #4 on: March 03, 2017, 07:49:40 AM »
        Thanks, you pointed me in the right direction -- I found a site that had code to remove wildcard-selected subfolders recursively, which works perfectly for the 10,000s of subfolders I need to manage:

        Code: [Select]

        FOR /d /r . %%d in (*temp *_backup) do @if exist "%%d" echo "%%d" && RD /s/q "%%d"


        Squashman



          Specialist
        • Thanked: 134
        • Experience: Experienced
        • OS: Other
        Re: Batch File Help
        « Reply #5 on: March 03, 2017, 10:16:23 AM »
        Thanks, you pointed me in the right direction -- I found a site that had code to remove wildcard-selected subfolders recursively, which works perfectly for the 10,000s of subfolders I need to manage:

        Code: [Select]

        FOR /d /r . %%d in (*temp *_backup) do @if exist "%%d" echo "%%d" && RD /s/q "%%d"

        Why are you checking if it exists?  It does exist.  The FOR command would not output the folder name unless it existed.

        patio

        • Moderator


        • Genius
        • Maud' Dib
        • Thanked: 1769
          • Yes
        • Experience: Beginner
        • OS: Windows 7
        Re: Batch File Help
        « Reply #6 on: March 03, 2017, 01:22:57 PM »
        Yer killin me Squash....
        " Anyone who goes to a psychiatrist should have his head examined. "

        Squashman



          Specialist
        • Thanked: 134
        • Experience: Experienced
        • OS: Other
        Re: Batch File Help
        « Reply #7 on: March 03, 2017, 07:28:44 PM »
        Yer killin me Squash....
        Does that mean I can quit my day job?

        patio

        • Moderator


        • Genius
        • Maud' Dib
        • Thanked: 1769
          • Yes
        • Experience: Beginner
        • OS: Windows 7
        Re: Batch File Help
        « Reply #8 on: March 03, 2017, 10:47:10 PM »
        Absolutely...have at it...
        " Anyone who goes to a psychiatrist should have his head examined. "

        Rodriguez

          Topic Starter


          Starter

          • Experience: Experienced
          • OS: Other
          Re: Batch File Help
          « Reply #9 on: March 10, 2017, 07:00:49 AM »
          Why are you checking if it exists?  It does exist.  The FOR command would not output the folder name unless it existed.

          I didn't write the whole syntax, I have only adjusted the wildcard part to search for the folders I need to remove.  If you can suggest a simpler syntax, I'd be happy to try it out, thanks.