A VBScript is receiving input parameters containing spaces in both the path and filename:
SOURCE = "c:\temp\testabc"
TARGET = "F:\work\dir space"
PARM = "Test file.txt"
DEST = TARGET & "\" & PARM
'…
fso.CopyFile SOURCE, DEST
The DEST
would look like this: "F:\work\dir space"\"Test file.txt"
, but VBScript produces an error:
Number of the Error and Description is 52 Bad file name or number
The copy
command has no issues when I do this:
copy "c:\temp\testabc" "F:\work\dir space"\"Test file.txt"
I cannot control the directory nor the file name as I am converting a batch script to use VBScript. Any ideas how I can copy to a destination that contain spaces in both the path and filename WITHOUT calling the xcopy
or copy
commands?
======================================================================== Adding more information, I tried what you had suggested, but I am still getting the same error. The script is executed via the command prompt, eg.,
cscript.exe test001.vbs "F:\Work\datafile.txt"
Code snippet:
…
Set fso = CreateObject("Scripting.FileSystemObject")
Dest = fso.BuildPath(Target, Parm)
…
Do While retry_counter < retry_max
WScript.Echo "Retry count ", retry_counter
fso.CopyFile Source, Dest
if Err.Number <> 0 Then
Wscript.Echo "Number of the Error and Description is ", Err.Number, " ", Err.Description
Err.Clear
End if
retry_counter = retry_counter + 1
WScript.echo now()
WScript.Sleep retry_sleeper
WScript.echo now()
Loop
…
Display listing:
--------------------------------------------
Display dictionary contents :
my_id : "someuser"
my_source : "c:\temp\testabc"
my_target : "F:\work\dir space"
my_parm : "Test file.txt"
my_idt : A12175803
my_idtu : IDTU5803
--------------------------------------------
--------------------------------------------
Display variable contents :
Source: "c:\temp\testabc"
Target: "F:\work\dir space"
Parm: "Test file.txt"
Dest: "F:\work\dir space"\"Test file.txt"
--------------------------------------------
Retry count 0
Number of the Error and Description is 52 Bad file name or number
1/13/2019 5:49:05 PM
1/13/2019 5:49:10 PM
Retry count 1
....