Hi,
Is there a way i can use forfiles to delete folders in a batch file please? If not can you please point me in the right direction to something that can.
Thanks![]()

Hi,
Is there a way i can use forfiles to delete folders in a batch file please? If not can you please point me in the right direction to something that can.
Thanks![]()
Last edited by FN-GM; 7th August 2011 at 08:04 PM.


On linux, you'd use find, which can find files according to rules like age, modification time, name, size etc. and then either list them, or execute a command (such as rm, or whatever you delete files with in windows-land) - recent versions of find actually include an option to delete the file, so you don't have to fork a copy of rm.
Luckily, find is available on windows too.
FN-GM (7th August 2011)

folders in a bath, don't they just get wet and soggy?
Ben

Not exactly what you want but this does files based on their age:
/D -1 is files that are over one day oldCode:FORFILES /P "C:\Folder" /S /D -1 /C "cmd /c del @path"
edit: obviously this shouldn't be mention but I can't figure out how to turn it off, [at]path" is what it should say.
Last edited by morganw; 7th August 2011 at 10:33 PM.

I think it's a bug in vBulletin as I often have the same issue with @echo off in batch files. Perhaps it might be worth mentioning it to @ZeroHour?![]()
Do mentions generate email notifications?
If so @pat might be disappointed when he gets here.

Got files copied thanks
I had it as well, reported it here: Code Wrapper and mentions


Here's a PowerShell script which does the same thing (should you need it)....
Remove the -WhatIf on the fifth line to actually delete the files.Code:$date = (Get-Date).AddDays(-10) $files = Get-ChildItem "C:\Temp" | Where { !$_.PSIsContainer } foreach($file in $files) { if ($file.LastAccessTime -lt $date) { Remove-Item -Path $file.FullName -WhatIf } }


^ Only files.
Edit. Just noticed you said folders, not files in your post.![]()
Last edited by Arthur; 7th August 2011 at 11:51 PM.

If the files are already gone from the folder, perhaps by using the powershell example for FORFILES, you could use:
...which would only delete it if it is empty.Code:RD C:\Folder
Last edited by morganw; 8th August 2011 at 09:46 AM.

so nobody has one. I will see if i can find something that makes the initial backup that will put it into a zip and use the above to get rid of the old backups.
Thanks![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)