-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclear windows Temp files.vbs
42 lines (31 loc) · 1.34 KB
/
clear windows Temp files.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Dim wshShell, objFSO, intCounter
' Get folder paths for the folders using environment variables
Set wshShell = CreateObject("WScript.Shell")
strPath = wshShell.ExpandEnvironmentStrings("%WINDIR%") & "\Temp"
Set wshShell = Nothing
' For each specified folder - Call EmptyFolder() to delete all files and subfolders
Set objFSO = CreateObject("Scripting.Filesystemobject")
If objFSO.FolderExists(strPath) Then
Call EmptyFolder(strPath)
End If
Function EmptyFolder(strFolderPath)
Dim objFSO, objCurrentFolder, colFilesInFolder, objFile, colFoldersInFolder, objFolder
Set objFSO = CreateObject("Scripting.Filesystemobject")
If objFSO.FolderExists(strFolderPath) Then
Set objCurrentFolder = objFSO.GetFolder(strFolderPath)
Set colFilesInFolder = objCurrentFolder.Files
' Delete all files in the folder
For Each objFile In colFilesInFolder
On Error Resume Next
objFSO.DeleteFile(objFile), True
Next
' Try to delete all subfolders and their containing files
Set colFoldersInFolder = objCurrentFolder.SubFolders
For Each objFolder In colFoldersInFolder
On Error Resume Next
DeleteFilesInFolder(objFolder.Path)
objFSO.DeleteFolder(objFolder), True
Next
End If
Set objFSO = Nothing
End Function