Jump to content

VBS set path variable


Recommended Posts

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


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

Try this it list the first instance of \Windows\System32 then exits the loop

Const 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
Next

This will list all instances of Windows\System32 on the local computer

Const 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
Next

This will list the first instance of Widows\System32\Shell32.dll then exits the loop

Const 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
Next

This will list all the instances of Widows\System32\Shell32.dll on the local computer

Const 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...