0

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?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • 2
    What error do you get when you don't hardcode the path? – Pankaj Jaju Dec 11 '17 at 12:41
  • 2
    You may not have permission to create a folder of the given location. Try to create manually and check. – ramkumar-yoganathan Dec 12 '17 at 02:54
  • Panka, I got the error "Cannot create Folder. The path is incorrect" It was something like this. I cannot acces the computer since friday, but I remember that the error was something like this. My feeling was that the script couldn't create the folder cause it was a wrong path, but as I mentioned in the question, writting the same path explicitly in the function worked fine. – markk borras Dec 13 '17 at 10:08
  • So, are you trying to say that the only difference between the code that worked and the code that didn't work is where you moved the literal path string from a variable to just putting it directly into the function call? Is your code example simplified from your actual working code, and if so, perhaps your variable is getting changed somewhere? – BoffinBrain Dec 22 '17 at 13:15

1 Answers1

-1

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")
mada
  • 67
  • 1