techobsl
14-09-2015, 10:24
Здравствуйте.
Есть скрипт удаления файлов старше 10 дней, помогите пожалуйста его исправить или дописать, чтобы удалял до минимума, допустим, если один файл в папке остался и его не удалять даже если старше 10-ти дней, иначе все бэкапы потереть может, если вдруг бэкапы перестали делаться. Бэкапы делаются sql с Linux машины.
path = "D:\Backup\sql"
killdate = date() - 10
arFiles = Array()
set fso = createobject("scripting.filesystemobject")
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 "Unable to delete: " & arFiles(n).path
else
nDeleted = nDeleted + 1
end if
on error goto 0
next
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
Есть скрипт удаления файлов старше 10 дней, помогите пожалуйста его исправить или дописать, чтобы удалял до минимума, допустим, если один файл в папке остался и его не удалять даже если старше 10-ти дней, иначе все бэкапы потереть может, если вдруг бэкапы перестали делаться. Бэкапы делаются sql с Linux машины.
path = "D:\Backup\sql"
killdate = date() - 10
arFiles = Array()
set fso = createobject("scripting.filesystemobject")
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 "Unable to delete: " & arFiles(n).path
else
nDeleted = nDeleted + 1
end if
on error goto 0
next
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