1.

Solve : File Deletion by date?

Answer»

Hi

Operating System : XP Pro

I wish to create a batch script that will AUTO delete *.avi files from my computer that are more than 2 (configurable) weeks old. The files are created from my security IP Camera's and can get rather large consuming LOTS of disk space.

The files are stored in a number of sub-directories on my computer and I plan to execute the script upon system startup.

Help much appreciated

PJBatch files do not have the functions to do date/time arithmetic unless you are prepared to WRITE a boatload of IF statements. Using a Windows Script would be a better solution. Perhaps this little script from my snippet closet can help you out:

Code: [Select]Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("FolderName") ' See note 1 below
Set colSubFolders = f.SubFolders

For Each objFolder in colSubFolders
ShowFiles objFolder
Next

Sub ShowFiles(Fld)
Set k = fso.GetFolder(Fld)
Set s = k.SubFolders
Set kf = k.Files

For Each objFile In kf
If objFile.DateCreated < date - 14 Then
If UCase(fso.GetExtensionName(objfile)) = "AVI" Then
Wscript.Echo objFile & " " & objFile.DateCreated 'See note 2 below
End If
End If
Next

For Each SubFolder In s
ShowFiles SubFolder
Next
End Sub

Note 1: replace FolderName with the top level directory where the AVI files live. SAVE the script with a VBS extension. To run, enter cscript Scriptname.vbs at a COMMAND prompt.

Follow the instructions for Note 1 above. Run the script, if you like what you see, follow the instructions for Note 2.

Note 2: replace entire line with fso.DeleteFile objFile, True
Note 3: You can use the task scheduler or the startup folder to have the script run at startup, but have the script run with wscript instead of cscript

Good luck. 8-)



Discussion

No Comment Found