General discussion

Locked

automatically delete files

By ppoll ·
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

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by p.j.hutchison In reply to automatically delete file ...

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

Collapse -

by carquiza In reply to automatically delete file ...

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.

Back to Windows Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums