Discussion Locked

automatically delete files

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm trying to set up a batch file to automatically delete files in a temporary directory and it's subdirectories on the network. But I only want it to delete anything that hasn't been modified in over a month. Is there any way to do this with dos commands, or is there someother way to do it? I'm not really too familiar with DOS.

Thanks

2 replies

by p.j.hutchison

You be best using VBScript (you need WSH installed to run VBS files) and use the FileSystemObject so that you can manipulate files etc.

by carquiza

Here is a vb script below.

Option Explicit
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
DeleteFiles fso.GetFolder("C:\Test") '<----- Change this folder name to match with your case.
Sub DeleteFiles(srcFolder)
Dim srcFile
If srcFolder.Files.Count = 0 Then
Wscript.Echo "No File to Delete"
Exit Sub
End If
For Each srcFile in srcFolder.Files
'If DateDiff("d", Now, srcFile.DateCreated) < -7 Then
fso.DeleteFile srcFile, True
'End If
Next
Wscript.Echo "Files Deleted successful"
End Sub

Hope this helps.

This discussion is closed to new replies.