I need to check to see if a path is valid....I want to verify that"C:/program Files/superprogram/setup.exe " is a valid program and return a result a message should thatnot a valid path...
VB ScriptVisual Basic Classic
Last Comment
GrahamSkan
8/22/2022 - Mon
rettiseert
Hui, try this:
dim filesys
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("c:\somefile.txt") Then
msgbox "The path is valid"
else
msgbox "The path is NOT valid"
end if
GrahamSkan
Or
If Dir$("C:\MyFolder", vbDirectory) = "" Then
MsgBox "No such folder"
Else
MsgBox "The folder exists"
End If
VBClassicGuy
Bowing to GrahamSkan's superior knowledge, I'd like to approve his method, but humbly offer one tiny improvement. Change:
Dir$("C:\MyFolder", vbDirectory) = ""
to
Len(Dir$("C:\MyFolder", vbDirectory) )
My boss years ago did a very comprehensive test to see what VB statements were the fastest. The Len statement was much faster than string comparison, even to an empty string. Just a sidebar, he also found that the Instr statement was among the fastest, and the Val(text) statement was among the slowest.
dim filesys
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("c:\somefile.txt") Then
msgbox "The path is valid"
else
msgbox "The path is NOT valid"
end if
-=-=-=-
I've tried this, with the length of the program in a loop, sometimes it works, sometimes it doesnt...
-=-=-=
vbaclassicguy,
I will jave to try this tmrw...
Len(Dir$("C:\MyFolder", vbDirectory) )
If Dir$("C:\MyFolder", vbDirectory) = "" Then
MsgBox "No such folder"
Else
MsgBox "The folder exists"
End If
GlobaLevel
ASKER
mistyped...
I've tried this, with the length of the program in a loop, sometimes it works, sometimes it doesnt...
If Dir$("C:\MyFolder", vbDirectory) = "" Then
MsgBox "No such folder"
Else
MsgBox "The folder exists"
End If
dim filesys
Set filesys = CreateObject("Scripting.Fi
If filesys.FileExists("c:\som
msgbox "The path is valid"
else
msgbox "The path is NOT valid"
end if