Computer Hope
Microsoft => Microsoft DOS => Topic started by: Rodriguez 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.
-
Look at the FORFILES command. It has the date option you need.
-
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 ?
-
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
-
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:
FOR /d /r . %%d in (*temp *_backup) do @if exist "%%d" echo "%%d" && RD /s/q "%%d"
-
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:
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.
-
Yer killin me Squash....
-
Yer killin me Squash....
Does that mean I can quit my day job?
-
Absolutely...have at it...
-
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.