Question : Check folder and delete any files if older than one week

I have copied files to a network share but I would like for a function that can look at that network share and delete files that are older than 1 week how can I do that in some dos based command?

Answer : Check folder and delete any files if older than one week

Following script (save as .vbs) and modify the 'strDir' value. Check the script by uncommenting the echo statements.

Dim fso, f, f1, fc, strComments, strScanDir

strDir = "D:\myDir"

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(strDir)
Set fc = f.Files

For Each f1 in fc
      If DateDiff("d", f1.DateCreated, Date) > 7 Then
            'strComments = strComments & f1.name & " " & f1.DateCreated & vbCrLf
            fso.DeleteFile(f1)
      End If
Next

'wscript.echo strComments
Random Solutions  
 
programming4us programming4us