DougInCanada
Technical User
I'm trying to run a script that will delete files in a specific folder based on the date the file was created:
[tt]Set fso = CreateObject("scripting.filesystemobject")
'on error resume Next
dttoday = Date
tmnow = Time
dtold = DateAdd("d", -30, dttoday) 'files older than 30 days will be deleted
Set LogFile = fspenTextFile("C:\scripts\FilePurge.log", 2, True)
LogFile.WriteLine ("Started --" & Date & " " & Time)
Set fldr = fso.GetFolder("C:\Users\svc_protect\AppData\Local\Temp")
Set files = fldr.Files
LogFile.WriteLine(fldr.path)
for each file in files
if file.datecreated < dtold then
LogFile.WriteLine(" DELETED - " & file.name & " Date Created: " & file.datecreated)
file.delete
end If
Next
set subfolders = nothing
set files = Nothing
LogFile.WriteLine ("Ended --" & Date & " " & Time)[/tt]
The problem is that I get a'permissions denied' error on the file.delete line.
The user that I'm running the script under has full access to the folder and the underlying files.
Is there any way to force the deletion?
[tt]Set fso = CreateObject("scripting.filesystemobject")
'on error resume Next
dttoday = Date
tmnow = Time
dtold = DateAdd("d", -30, dttoday) 'files older than 30 days will be deleted
Set LogFile = fspenTextFile("C:\scripts\FilePurge.log", 2, True)
LogFile.WriteLine ("Started --" & Date & " " & Time)
Set fldr = fso.GetFolder("C:\Users\svc_protect\AppData\Local\Temp")
Set files = fldr.Files
LogFile.WriteLine(fldr.path)
for each file in files
if file.datecreated < dtold then
LogFile.WriteLine(" DELETED - " & file.name & " Date Created: " & file.datecreated)
file.delete
end If
Next
set subfolders = nothing
set files = Nothing
LogFile.WriteLine ("Ended --" & Date & " " & Time)[/tt]
The problem is that I get a'permissions denied' error on the file.delete line.
The user that I'm running the script under has full access to the folder and the underlying files.
Is there any way to force the deletion?