FN-GM Posted August 7, 2011 Posted August 7, 2011 (edited) 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 Edited August 7, 2011 by FN-GM
tom_newton Posted August 7, 2011 Posted August 7, 2011 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. 1
plexer Posted August 7, 2011 Posted August 7, 2011 folders in a bath, don't they just get wet and soggy? Ben
FN-GM Posted August 7, 2011 Author Posted August 7, 2011 folders in a bath, don't they just get wet and soggy? Ben Opps typo corrected
morganw Posted August 7, 2011 Posted August 7, 2011 (edited) Not exactly what you want but this does files based on their age: FORFILES /P "C:\Folder" /S /D -1 /C "cmd /c del @path" /D -1 is files that are over one day old 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. Edited August 7, 2011 by morganw
Arthur Posted August 7, 2011 Posted August 7, 2011 obviously this shouldn't be mention but I can't figure out how to turn it off, [at]path" is what is should say. 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?
morganw Posted August 7, 2011 Posted August 7, 2011 Do mentions generate email notifications? If so @pat might be disappointed when he gets here.
FN-GM Posted August 7, 2011 Author Posted August 7, 2011 Not exactly what you want but this does files based on their age: FORFILES /P "C:\Folder" /S /D -1 /C "cmd /c del @path" /D -1 is files that are over one day old 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. Got files copied thanks 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? I had it as well, reported it here: http://www.edugeek.net/forums/edugeek-net-site-problems/80555-code-wrapper-mentions.html
Arthur Posted August 7, 2011 Posted August 7, 2011 If so @pat might be disappointed when he gets here. Especially if she/he is going to be deleted! http://i.imgur.com/mWw1G.jpg
Arthur Posted August 7, 2011 Posted August 7, 2011 Here's a PowerShell script which does the same thing (should you need it).... $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 } } Remove the -WhatIf on the fifth line to actually delete the files.
FN-GM Posted August 7, 2011 Author Posted August 7, 2011 Here's a PowerShell script which does the same thing (should you need it).... $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 } } Remove the -WhatIf on the fifth line to actually delete the files. Would this delete files or folders please?
Arthur Posted August 7, 2011 Posted August 7, 2011 (edited) ^ Only files. Edit. Just noticed you said folders, not files in your post. Edited August 7, 2011 by Arthur
FN-GM Posted August 7, 2011 Author Posted August 7, 2011 ^ Just files. Ah doesnt matter, thanks anyway
morganw Posted August 8, 2011 Posted August 8, 2011 (edited) If the files are already gone from the folder, perhaps by using the powershell example for FORFILES, you could use: RD C:\Folder ...which would only delete it if it is empty. Edited August 8, 2011 by morganw
FN-GM Posted August 12, 2011 Author Posted August 12, 2011 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
mac_shinobi Posted August 12, 2011 Posted August 12, 2011 does it have to be for files or can it be power shell / vbs ?
FN-GM Posted August 12, 2011 Author Posted August 12, 2011 does it have to be for files or can it be power shell / vbs ? Can be any of those if it does the job.
mac_shinobi Posted August 13, 2011 Posted August 13, 2011 Can be any of those if it does the job. 1. Is this on a unc path or a mapped network drive ?2. O.S wise is this going to be run direct on the server or as a startup/logon script on the clients and what OSes are we talking about3. Have you got a guide on directory structure and does the age of* Files* Folders* Sub-FoldersCount when taking into consideration age of the date last modified propertys ??
FN-GM Posted August 13, 2011 Author Posted August 13, 2011 1. Is this on a unc path or a mapped network drive ?2. O.S wise is this going to be run direct on the server or as a startup/logon script on the clients and what OSes are we talking about3. Have you got a guide on directory structure and does the age of* Files* Folders* Sub-FoldersCount when taking into consideration age of the date last modified propertys ?? 1. None its a local drive on a server 2. It will run as a scheduled task on the server 3. Its the SIMS Doc storage so that will give you an idea. Folder> Lots of subfolders > More Sub Folders.
matt40k Posted August 13, 2011 Posted August 13, 2011 3. Its the SIMS Doc storage so that will give you an idea. Folder> Lots of subfolders > More Sub Folders. Don't touch the DocStorage folder. Go into SIMS and run the unlinked documents routine if you really want to tidy it up. Still I would get the Data Manager to do it.
FN-GM Posted August 13, 2011 Author Posted August 13, 2011 Don't touch the DocStorage folder. Go into SIMS and run the unlinked documents routine if you really want to tidy it up. Still I would get the Data Manager to do it. I am cleaning up the backups of the sims DocStorge not the original.
matt40k Posted August 15, 2011 Posted August 15, 2011 Bit confussed why you backup DocStorage (by dbAttach), I normally just do a robocopy\ntbackup\whatever of the main docstorage. I can make TidyBackups support it if you want.
FN-GM Posted August 15, 2011 Author Posted August 15, 2011 Bit confussed why you backup DocStorage (by dbAttach), I normally just do a robocopy\ntbackup\whatever of the main docstorage. I can make TidyBackups support it if you want. Its all put in by another organisation under the instructions of capita. They wont support it if i mess about with the backup they set.
matt40k Posted August 15, 2011 Posted August 15, 2011 Mmm... I question why they would be copying around 20gb each time for no reason - reports don't tent to be that import - if I spend a lot of time creating one, I export it. If they manage it, I'd ask them to tidy it. After all, you don't know what's safe to delete
FN-GM Posted August 15, 2011 Author Posted August 15, 2011 Mmm... I question why they would be copying around 20gb each time for no reason - reports don't tent to be that import - if I spend a lot of time creating one, I export it. If they manage it, I'd ask them to tidy it. After all, you don't know what's safe to delete I think your missing the point, im only deleting old backups not the stuff itself.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now