Jump to content

Recommended Posts

Posted (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 by FN-GM
Posted

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.

  • Thanks 1
Posted (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 by morganw
Posted
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? :)

Posted
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

Posted

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.

Posted
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?

Posted (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 by morganw
Posted

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 :)

Posted
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 ??
Posted
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.

Posted
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.

Posted
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.

Posted
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.
Posted
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.

Posted
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 ;)
Posted
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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...