Questo che ho appena fatto e provato, funziona:
Codice:
' ATTENZIONE CHE I FILE SARANNO CANCELLATI DEFINITIVAMENTE
' NON ANDRANNO NEL CESTINO!!!
' directory principale (MODIFICARE IL PERCORSO)
path = "c:\AAA"
' cancella file più vecchi di 7 giorni (MODIFICARE IL N°)
killdate = date() - 7
arFiles = Array()
set fso = createobject("scripting.filesystemobject")
' sub che cancella i file; il 4° parametro indica se analizzare anche le sottodirectory
' se SI allora scrivere true, se NO allora scrivere false
SelectFiles path, killdate, arFiles, true
nDeleted = 0
for n = 0 to ubound(arFiles)
on error resume next
arFiles(n).delete true
if err.number <> 0 then
wscript.echo "Impossibile cancellare: " & arFiles(n).path
else
nDeleted = nDeleted + 1
end if
on error goto 0
next
msgbox nDeleted & " di " & ubound(arFiles)+1 & " file vecchi cancellati"
sub SelectFiles(sPath,vKillDate,arFilesToKill,bIncludeSubFolders)
on error resume next
set folder = fso.getfolder(sPath)
set files = folder.files
for each file in files
dtlastmodified = null
on error resume Next
dtlastmodified = file.datelastmodified
on error goto 0
if not isnull(dtlastmodified) Then
if dtlastmodified < vKillDate then
count = ubound(arFilesToKill) + 1
redim preserve arFilesToKill(count)
set arFilesToKill(count) = file
end if
end if
next
if bIncludeSubFolders then
for each fldr in folder.subfolders
SelectFiles fldr.path,vKillDate,arFilesToKill,true
next
end if
end sub
Modificare dove ho scritto ... ovvero il percorso della directory, il numero dei giorni e nella chiamata alla sub modificare il 4° parametro (true o false a seconda se si vuole analizzare anche le sottodirectory).
Salva il file come .vbs ...