1.

Solve : Delete files older than?

Answer»

Need a simple DOS BATCH program which deletes files older than a certain date.You can do this indirectly with XCOPY using the /d:mm-dd-yy switch. Use XCOPY to copy all the files you want to keep to a temp directory. Delete all the files in the original directory, then move the copied files back. Finally delete the temp directory. Use XCOPY /? at the command line for details on the /d switch.

Messy but effective.

Hope this helps. Thank you but a bit messy. I really wanted code like the following.

erase c:/dirname/*.* where time < 7days

Just need the right syntax

Thanks
NormThen you need to use VB Script not DOS Batch.Quote

I really wanted code like the following.

erase c:/dirname/*.* where time < 7days


[SIGH] wouldn't we all!

Not as messy but still effective:

Dim FSO, f, f1, fc
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec) ' <== Change folderspec to your requirements (put in quotes)
Set fc = f.Files
For Each f1 in fc
If DateDiff("d", f1.DateLastModified, Now) > 7 Then
fso.DeleteFile(f1)
End If
Next
Set fso = Nothing
WScript.Quit


Note: you can also use the DateCreated or DateLastAccessed properties

Save as a VBS file, then DOUBLE click file to run.

Good Luck. Thank you both for your help.
I will give it a go.
Normhello,

maybe this can help u :

for /F "tokens=1,2,3,4,5* delims=/ " %a in ('dir') do if "%c%b%a" LSS "20050420" echo %f



Discussion

No Comment Found