Deleting Files by Date

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Guest
Folks,
I'm in a quandry. I have an NT application which has a habit of creating large numbers of small files (50 bytes or so each)in a specific subdirectory. I'd like to periodically delete all files in this subdirectory which are older than 7 days. Does anyone know of a commandline utility which I can run from the scheduler to do this task?
 
Put this in the "must-be-a-better-way-but-this-will-work" catagory. God this is ugly....

For this example I'm going to assume they are text files:

1. Set the Archive bit on all the files in the directory:

attrib *.txt +a

2. use Xcopy's /D switch to copy files with the date you want delete, to make duplicates of them:

XCOPY *.TXT *.XXX /D:01-01-2001

3. Clear the Archive bit on all text files in the folder:

Attrib *.txt -a

4. Copy back from the backups over the top of the originals.

XCOPY *.XXX *.TXT

5. Delete everything that has the archive bit set:

Del *.* /a:a

You will be left with just the files before the date in question. When you are done you may want to set the archive bit again in case you are running some form of backup that depends on it.

Again it's ugly but it should work.