MioKawaii Posted November 29, 2006 Share Posted November 29, 2006 I'm trying to learn VBS by converting a CMD file but.................How do you search for a file and SET the location as a variable in VBS?For instance CMD:FOR %%I IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%I:\WhateverFolder\WhateverFile.txt SET WhateverLoc=%%I:\WhateverFolder Link to comment Share on other sites More sharing options...
gunsmokingman Posted November 29, 2006 Share Posted November 29, 2006 I'm trying to learn VBS by converting a CMD file but.................How do you search for a file and SET the location as a variable in VBS?For instance CMD:FOR %%I IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%I:\WhateverFolder\WhateverFile.txt SET WhateverLoc=%%I:\WhateverFolderTry this it list the first instance of \Windows\System32 then exits the loopConst Removable = 1, Fixed = 2, CD_DVD = 4 Dim Act : Set Act = CreateObject("Wscript.Shell") Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject") Dim ChkFolder, Drv, StrD Set Drv = Fso.Drives For Each StrD In Drv If StrD.DriveType = Fixed Then If Fso.FolderExists(StrD & "\Windows\System32") Then Act.Popup "Found The System32 Folder On " & StrD ,5,"Confirm",4128'/-> Set The Only Found Instance Of Windows\System32 As The New Varible ChkFolder = StrD & "\Windows\System32" Exit For End If End If NextThis will list all instances of Windows\System32 on the local computerConst Removable = 1, Fixed = 2, CD_DVD = 4 Dim Act : Set Act = CreateObject("Wscript.Shell") Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject") Dim ChkFolder, Drv, StrD Set Drv = Fso.Drives For Each StrD In Drv If StrD.DriveType = Fixed Then If Fso.FolderExists(StrD & "\Windows\System32") Then Act.Popup "Found The System32 Folder On " & StrD ,5,"Confirm",4128'/-> Set The Last Found Instance Of Windows\System32 As The New Varible ChkFolder = StrD & "\Windows\System32" End If End If NextThis will list the first instance of Widows\System32\Shell32.dll then exits the loopConst Removable = 1, Fixed = 2, CD_DVD = 4 Dim Act : Set Act = CreateObject("Wscript.Shell") Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject") Dim ChkFile, Drv, StrD Set Drv = Fso.Drives For Each StrD In Drv If StrD.DriveType = Fixed Then If Fso.FileExists(StrD & "\Windows\System32\Shell32.dll") Then Act.Popup "Found The Shell32.dll Folder On " & StrD ,5,"Confirm",4128'/-> Set The First Found Instance Of Windows\System32\Shell32.dll As The New Varible ChkFile = StrD & "\Windows\System32" Exit For End If End If NextThis will list all the instances of Widows\System32\Shell32.dll on the local computerConst Removable = 1, Fixed = 2, CD_DVD = 4 Dim Act : Set Act = CreateObject("Wscript.Shell") Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject") Dim ChkFile, Drv, StrD Set Drv = Fso.Drives For Each StrD In Drv If StrD.DriveType = Fixed Then If Fso.FileExists(StrD & "\Windows\System32\Shell32.dll") Then Act.Popup "Found The Shell32.dll Folder On " & StrD ,5,"Confirm",4128'/-> Set The Last Found Instance Of Windows\System32\Shell32.dll As The New Varible ChkFile = StrD & "\Windows\System32" End If End If Next Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now