I want to delete the oldest file in a folder. I'm using this script:
path = "C:\TEMP\TEST"
killdate = date() - 20
arFiles = Array()
set fso = createobject("scripting.filesystemobject")
SelectFiles path, killdate, arFiles
for n = 0 to ubound(arFiles)
set f = arFiles
f.delete true
next
sub SelectFiles(sPath,vKillDate,arFilesToKill)
set folder = fso.getfolder(sPath)
set files = folder.files
for each file in files
on error resume Next
dtcreated = file.datelastmodified
on error goto 0
if not isnull(dtcreated) Then
if dtcreated < vKillDate then
count = ubound(arFilesToKill) + 1
redim preserve arFilesToKill(count)
set arFilesToKill(count) = file
end if
end if
next
end sub
Question no 1: Is there an easier way?
Question no 2: How can i exclude 2 files. I've tried with:
if f = "file1.txt" then
wscript.quit
end if
if f = "file2.txt" then
wscript.quit
end if
but this doesn't work. Any ideas?
path = "C:\TEMP\TEST"
killdate = date() - 20
arFiles = Array()
set fso = createobject("scripting.filesystemobject")
SelectFiles path, killdate, arFiles
for n = 0 to ubound(arFiles)
set f = arFiles
f.delete true
next
sub SelectFiles(sPath,vKillDate,arFilesToKill)
set folder = fso.getfolder(sPath)
set files = folder.files
for each file in files
on error resume Next
dtcreated = file.datelastmodified
on error goto 0
if not isnull(dtcreated) Then
if dtcreated < vKillDate then
count = ubound(arFilesToKill) + 1
redim preserve arFilesToKill(count)
set arFilesToKill(count) = file
end if
end if
next
end sub
Question no 1: Is there an easier way?
Question no 2: How can i exclude 2 files. I've tried with:
if f = "file1.txt" then
wscript.quit
end if
if f = "file2.txt" then
wscript.quit
end if
but this doesn't work. Any ideas?