I need to create a script in VBS to remove all files from the Desktop in Windows, except files that contain .rdp and .exe extensions.
This is the script that has been created so far (it works, but it deletes everything):
Dim objShell, objFolder, objFolderItem, objFS, colSubFolders, Folder
Const USER_PROFILE = &H28&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(USER_PROFILE)
Set objFolderItem = objFolder.Self
vPastaDeletar = objFolderItem.Path & "\Desktop"
Const DeleteReadOnly = TRUE
Dim Folder
Set objFS = CreateObject("Scripting.FileSystemObject")
ObjFS.DeleteFile(vPastaDeletar & "\*.*"),DeleteReadOnly
Set objFolder = objFS.GetFolder(vPastaDeletar)
Set colSubFolders = objFolder.Subfolders
On Error Resume Next
For Each Folder in objFolder.Subfolders
if Folder.name<> "Desktop" then
Folder.Delete
end if
Next
How can I edit the script to only preserve/skip files with .rdp and .exe extension?
Thanks in advance!