I was trying to write a code to check for a specific file if it is existing in a folder and subfolder in any subfolder DESKTOP in c: users*.* (= all users directories). And if the file is existing in any folder the script will delete the file. Option Explicit Dim Shell, FSO, DesktopPath Dim objShortcutFile, objDesktopFolder, objDesktopSubFolder, Folder, strSysDrive Set Shell = CreateObject('WScript.Shell') Set FSO = CreateObject('Scripting.FileSystemObject') strSysDrive = Shell.ExpandEnvironmentStrings('%SystemDrive%') Set Folder = FSO.GetFolder(strSysDrive & ' Users') msgbox Folder & ' sample1.lnk' For Each objDesktopFolder in Folder. Medical terminology made easy fourth edition masteringmicrobiology. SubFolders If FSO.FileExists(Folder & ' sample1.lnk') Then FSO.DeleteFile Folder & ' sample1.lnk' msgbox 'success' Else msgbox 'not existing' End If Next. Folder is the C: Users folder object; objDesktopFolder is the folder object for each folder directly in C: Users, e.g. ![]() C# Delete All Files In DirectoryC: Users user1 - not further levels of subfolders e.g. Freepbx install unistim to analog. C: Users user1 Desktop (so it's a misleading name as it is not the desktop folder). If you only want to look directly on the desktop, then just change this line (and any other line that uses that path): If FSO.FileExists(Folder & ' sample1.lnk') Then to: If FSO.FileExists(FSO.BuildPath(objDesktopFolder.Path, 'Desktop sample1.lnk')) Then If you also want to look through each folder that may exist on the desktop, then you'll have to perform the same sort of logic, e.g.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |