I've got a script that deletes all files and folders in a folder that are older than 14 days. However I'm sure it used to work but it's stopped working.
Code:
'**************************************
' Name: Remove Files Older than 14 Days From Common Folder
'
'**************************************
Set fso = CreateObject("Scripting.FileSystemObject")
olddate = DateAdd("d", -14, date)
'wscript.stdout.writeline "Today is " & Date
'wscript.stdout.writeline "Deleting files unaccessed since " & olddate
'wscript.stdout.writeline " "
'wscript.stdout.writeline "Connecting To FileShare "
Set folder = fso.GetFolder("E:\Company Folder\CommonPool") '("\\<Server>\d$\temp\archive")' Get the folder
'WScript.StdOut.Writeline "Getting a List of the Files"
Set fc = folder.Files
For Each f1 In fc
if f1.DateLastModified < olddate Then
'wscript.stdout.write "Removing: " & f1.DateLastModified & vbtab & f1.name & VbCrLf
fso.deletefile(f1)
End if
Next
Does this seem correct? or am I missing something.
Code:
'**************************************
' Name: Remove Files Older than 14 Days From Common Folder
'
'**************************************
Set fso = CreateObject("Scripting.FileSystemObject")
olddate = DateAdd("d", -14, date)
'wscript.stdout.writeline "Today is " & Date
'wscript.stdout.writeline "Deleting files unaccessed since " & olddate
'wscript.stdout.writeline " "
'wscript.stdout.writeline "Connecting To FileShare "
Set folder = fso.GetFolder("E:\Company Folder\CommonPool") '("\\<Server>\d$\temp\archive")' Get the folder
'WScript.StdOut.Writeline "Getting a List of the Files"
Set fc = folder.Files
For Each f1 In fc
if f1.DateLastModified < olddate Then
'wscript.stdout.write "Removing: " & f1.DateLastModified & vbtab & f1.name & VbCrLf
fso.deletefile(f1)
End if
Next
Does this seem correct? or am I missing something.