You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.7 KiB
Plaintext

'L<>scht tempor<6F>re Dateien, die <20>lter sind als ein Tag
'Gel<65>scht werden die Temp-Ordner und alle Dateien mit der Endung .tmp
Option Explicit
Dim wshshell,fso,i,Fnct
Dim strPath,strSystemFolder,strWinFolder,strTempFolder
'----------------------------- Objekte erzeugen --------------------------------
i = 0
On Error Resume Next
Do
err.Clear
i = i+1
Set wshshell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set Fnct = CreateObject("Install.Functions")
WScript.Sleep 1000
Loop Until Err.Number = 0 OR i > 30
If Err.Number <> 0 Then
WScript.Quit
End If
On Error Goto 0
'--------------------------- Standardpfade -------------------------------------
strPath = GetCurrentPath()
strSystemFolder = fso.GetSpecialFolder(1) & "\"
strWinFolder = fso.GetSpecialFolder(0) & "\"
strTempFolder = fso.GetSpecialFolder(2) & "\"
'------------------------------ Main -------------------------------------------
Call DeleteOldFiles(strTempFolder)
Call DeleteOldSubfolders(fso.GetSpecialFolder(2))
Call DeleteOldTmpFiles("c:\")
Call DeleteOldSubfolders("c:\System Volume Information")
Call DeleteOldSubfolders("c:\Program Files\Acronis\TrueImageHome\BartPE")
If fso.FileExists(strWinFolder & "user.dmp") Then
On Error Resume Next
fso.deleteFile(strWinFolder & "user.dmp")
On Error Goto 0
End If
'------------------------------- Funktionen ------------------------------------
Function GetCurrentPath()
Dim l_strScriptName
Dim l_strTemp
l_strScriptName = WScript.ScriptFullName
l_strTemp = WScript.ScriptName
GetCurrentPath = Left(l_strScriptName, Len(l_strScriptName) - Len(l_strTemp))
End Function
Function ExpandPath(p_strEnvironment,p_strDefault)
Dim l_strTemp
l_strTemp = wshshell.ExpandEnvironmentStrings(p_strEnvironment)
If l_strTemp = p_strEnvironment Then
l_strTemp = p_strDefault
End If
ExpandPath = l_strTemp
End Function
'L<>scht alle Dateien, die <20>lter sind als ein Tag aus dem angegebenen Ordner
Sub DeleteOldFiles(strFolder)
Dim Folder,AllTempFiles,File
Set Folder = fso.GetFolder(strFolder)
Set AllTempFiles = Folder.Files
For Each File in AllTempFiles
If DateDiff("d",File.DateLastModified,Date) > 0 Then
On Error Resume Next
Call File.Delete(True)
On Error Goto 0
End If
Next
End Sub
'L<>scht alle Unterordner, die <20>lter sind als ein Tag aus dem angegebenen Ordner
Sub DeleteOldSubfolders(strFolder)
Dim Folder,AllSubfolders,Subfolder
If fso.FolderExists(strFolder) Then
Set Folder = fso.GetFolder(strFolder)
Set AllSubfolders = Folder.Subfolders
On Error Resume Next ' Falls Zugriff verboten, knallt es hier
For Each Subfolder in AllSubfolders
If Err.Number <> 0 Then
Err.Clear
Exit Sub
End If
On Error Goto 0 ' Ende Zugriff verboten
If DateDiff("d",Subfolder.DateCreated,Date) > 0 Then
On Error Resume Next
Call fso.DeleteFolder(Subfolder,true)
On Error Goto 0
End If
Next
End If
End Sub
'L<>scht alle Dateien mit der Endung.tmp, die <20>lter sind als ein Tag aus dem angegebenen Ordner
' sowie aus allen Unterordnern
Sub DeleteOldTmpFiles(strFolder)
Dim Folder,AllTempFiles,File
Dim AllSubfolders,Subfolder
Set Folder = fso.GetFolder(strFolder)
Set AllSubfolders = Folder.Subfolders
On Error Resume Next
For Each Subfolder in AllSubfolders
DeleteOldTmpFiles(Subfolder.Path)
Next
On Error Goto 0
Set AllTempFiles = Folder.Files
For Each File in AllTempFiles
Dim bIsTmpFile
Dim strFilename
strFilename = LCase(File.Name)
bIsTmpFile = Instr(1,Right(strFilename,4),".tmp",0) > 0
If DateDiff("d",File.DateLastModified,Date) > 0 And bIsTmpFile Then
On Error Resume Next
Call File.Delete(True)
On Error Goto 0
End If
Next
End Sub