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
| Dim objDic
Dim oShell
Set objDic = CreateObject("Scripting.Dictionary")
' Define the files you need to delete
objDic.Add LCase("cacapipi.jpg.Ink"), ""
Set oShell = CreateObject("Wscript.Shell")
strUserProfile = oShell.ExpandEnvironmentStrings("%USERPROFILE%")
' This is where it will only search and delete in the logged on users profile
ShowFolderList(strUserProfile)
Function ShowFolderList(folderspec)
Dim fso, f, f1, s, sf
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set sf = f.SubFolders
For Each f1 in sf
ShowFolderList(f1.path)
ShowFileList(f1.path)
Next
End Function
Function ShowFileList(folderspec)
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
if objDic.Exists(LCase(f1.name)) then
fso.deletefile f1.path, true
end if
Next
End Function |
Partager