0

I cant get FORFILES to work for me. I run a .bat that backs up a few databases I have each day using this one example below.

COPY "X:\W Attendenance\C Crew Attendance\Attendance Control DB v4.xx.accdb" "X:\Supervisors Log\Backups\Attendance Bak\bak_%currdate%_Attendance Control DB v4.xx.accdb"

Then after running my backups I wanted to delete the old files that were older than five days by using the below example.

FORFILES /p "X:\Supervisors Log\Backups\Attendance Bak\" /d -5 /c "cmd /c del @path "

But what happens is it creates the backups but never deletes the old ones. What am I doing wrong?

Ken it still seems to not work. I changed the @file to @path and ran and I still have my backups. I also had another question, can I limit the delete to just files starting in bak_ ? and can I delete the file by its name because every backup starts with bak_ then the date mm-dd-yyyy_ then name of the file...

SoggyCashew
  • 69
  • 1
  • 4
  • 15
  • Shouldn't you use @path instead of @file? – Gabriel M May 14 '14 at 21:40
  • 1
    possible duplicate of [Batch file to delete files older than N days](http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days). If you look at the use of `forfiles` in the accepted answer to that question, you'll see it should be `@path` instead of `@file`. – Ken White May 14 '14 at 22:15

2 Answers2

0

This fixed it... Thanks for your help and links!

forfiles -p "X:\Supervisors Log\Backups\Attendance Bak" -s -m *.* -d -1 -c "cmd /c del @path"
SoggyCashew
  • 69
  • 1
  • 4
  • 15
0

On a side note that only is able to delete the File but Sometimes I needed to delete a folder and everything in it so I use:

FORFILES /P "H:\BACKUPS\bk_Operator_Rate_Program" /d -10 /c "cmd /c IF @isdir == TRUE rd /S /Q @path"
SoggyCashew
  • 69
  • 1
  • 4
  • 15