Good evening,
While searching on google for a code that will delte all files that are old more than xx days in a specific folder, I found out bellow code:
Sub DelOldFiles()
''Clear out all files over 7 days old from Dir_Path folder.
'
Dir_Path = "C:\Folder\SubFolder\"
iMaxAge = 7 ' Set the number of days
Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FolderExists(Dir_Path) Then 'Check that the folder exists
For Each oFile In oFSO.GetFolder(Dir_Path).Files
If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then 'Look at each file to check if it is older than 7 days
oFile.Delete
End If
Next
End If
End Sub
but unforunatelly is not working for me.
It pups up a error saying: Dir_Path = "C:\Folder\SubFolder\" --> VARIABLE NOT DEFINED.
Do you have any Idea how to handle it?
Best regards,
forfiett
I get a error
Bookmarks