Codename K
Codename K

Reputation: 744

Check if a string is folder path?

The following VBScript code checks if a string is folder path,

Set fso = CreateObject("Scripting.FileSystemObject")
if fso.FolderExists(folderpath) then
   'Do code
end if

But this works only if the actual folder exists. What is the VBScript code to check if a string is folder path when there is no actual folder found. Because, the folder will be created from the string after confirmation that the string structure is folder path.

Upvotes: 1

Views: 830

Answers (1)

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38775

Use .GetParentFolderName and .FolderExists to check if a full path has a valid head/prefix:

>> p = "c:\users\eh\pipapo"
>> WScript.Echo goFS.GetParentFolderName(p)
>> WScript.Echo goFS.FolderExists(goFS.GetParentFolderName(p))
>>
c:\users\eh
-1
>>

Upvotes: 3

Related Questions