среда, 20 октября 2010 г.

Удаляем старые файлы из папки:

Option Explicit
Dim fso, dTwoWeeksAgo
dTwoWeeksAgo = Date() - 14
wscript.echo dTwoWeeksAgo
Set fso = CreateObject("Scripting.FileSystemObject")
'DirWalk("C:\")               ' repeat this subroutine call with a different path to process more paths
'DirWalk("F:\users\data\")   ' like this.
DirWalk("d:\pub\shared")  ' and/or like this.
Sub DirWalk(parmPath)
Dim oSubDir, oSubFolder, oFile, n
   On Error Resume Next         ' We'll handle any errors ourself, thank you very much
   Set oSubFolder = fso.getfolder(parmPath)
   For Each oFile In oSubFolder.Files   ' look in the current dir
      If Err.Number <> 0 Then   ' if we got an error, just skip this entry
         Err.Clear
      ElseIf oFile.DateLastModified < dTwoWeeksAgo Then
         'Wscript.Echo "about to delete " & oFile.Path
        '''uncomment the next line when you are satisfied this script works properly
        fso.DeleteFile oFile.Path, True
      End If
   Next
   For Each oSubDir In oSubFolder.Subfolders
      DirWalk oSubDir.Path      ' recurse the DirWalk sub with the subdir paths
   Next
   On Error Goto 0              ' Resume letting system handle errors.
End Sub

После удаляем пустые папки:
start "delete old files" /w cscript /b C:\scripts\deleteoldfiles.vbs
for /f "usebackq delims==" %%d in (`"dir d:\pub\shared /ad/b/s | sort /R"`) do rd "%%d"

Скрипт не мой ... нашел в интернете.