VBScript cannot create folder

364 Views Asked by At

I have a simple script that perfectly works on a computer. The script is written in VBScript and ran using UFT (Unified Functional Testing).

Option Explicit
Dim objFSO, objFolder, strDirectory

strDirectory = "Path" 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(strDirectory)

However, when I try to run this code on another computer it didn't work. I changed the path to another path which corresponds to the new computer. The surprise comes when I try to run the code without using the variable strDirectory:

Option Explicit
Dim objFSO, objFolder, strDirectory

strDirectory = "Path" 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("path")

which works fine in the new computer.

Does anyone know why is this happening? How can a script work in a computer but not in another computer? And moreover, how can the script work in this new computer when not using the strDirectory variable to store the path?

1

There are 1 best solutions below

0
On

Try running using the entire path:

Option Explicit
Dim objFSO, objFolder, strDirectory

strDirectory = "Path" 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("C:\\path")