rosalin
Silver Member | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору '=========================================================== ' ' Function DelFilesDate(sFullPath, ndays) ' sFullPath - delete directory ' ndays - quantity of days after then file deleting ' COMMENT: delete temp files old "ndays" days ' '=========================================================== Function DelFilesDate(sFullPath, ndays) Dim lfsObject Dim lFileList Dim lFolder Dim lFile Set lfsObject = CreateObject("Scripting.FileSystemObject") 'Process contained files first If lfsObject.FolderExists(sFullPath) Then Set lFolder = lfsObject.GetFolder(sFullPath) Set lFileList = lFolder.Files ' Scan each file in the folder For Each lFile In lFileList ' Get the difference In days between the two dates Diff = DateDiff("d", lFile.DateLastModified, Now) If Diff >= ndays Then 'MsgBox lFile.Name lfsObject.DeleteFile(sFullPath & "\" & lFile.Name) End If Next If lFolder = WshShell.ExpandEnvironmentStrings("%TEMP%") Then 'Process subdirectories Set lSubFolders = lFolder.SubFolders For Each lSubFolder in lSubFolders NewSource = strSourceDir & "\" & lSubFolder.Name 'Recursive call to delete all subdirectories DelFiles NewSource 'Delete this directory lSubFolder.Delete Next Else End If End If 'Cleanup Set lfsObject = Nothing Set lFileList = Nothing Set lFolder = Nothing Set lFile = Nothing End Function |