Reputation: 2427
i'm trying to get a vbscript (cscript/vbs) to copy files from one network location (my tv show downloads folder) to another network location (my pvr).
i tried to use xcopy but ended up with "parse error" without any context. tried a few things like ensuring files that have spaces are quoted, etc. couldn't work it out.
i tried using scripting.filesystemobject's copyfile method, but this failed with a "bad file name or number" error and googling this one led to many, many dead ends.
i am currently trying to get robocopy to handle the copy since it's generally better than both of the above. but when run from within cscript using WScript.Shell's Run method, the destination, filename and parameters all "fall off".
So here's a snip of the copy part.
if dirmatch > "" then
fileFrom = quote(myloc) ' & fil.name) 'fil.name will not need to be quoted
fileTo = quote(dirmatch) ' puts double-quotes around things if they have spaces in the name
' copyCommand = "%comspec% /k xcopy " & fileFrom & " " & fileTo & " /C /D /Y" ' returns "parse error"
copyCommand = "%comspec% /k robocopy " & fileFrom & " " & fileTo & " " & fil.name & " /R:3 /W:10"' /MOV"
logmsg copyCommand
oShellApp.run copyCommand
else
logmsg "no matching directory found for: " & fil.name
end if
The fileFrom and fileTo are directories that I have previously calculated using filename parsing - just in the format of \\server\path\more path might have spaces\etc\etc
. fil.name is the file and it never has spaces - is dot seperated. The spaces in folder names is a requirement for matching reasons in another app I use.
So a given file copy command should look like this:
00:19: %comspec% /k robocopy \\qnap\qdownload\transmission\completed \\pvr\e\tv\MythBusters Mythbusters.S11E03.Hail.Hijinx.HDTV.x264-FQM.mp4 /R:3 /W:10
but robocopy in the new command window (e.g. cmd.exe /k
) throws up like this:
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Tue Oct 23 21:04:58 2012
Source : \\qnap\qdownload\transmission\completed\
Dest -
Files : *.*
Options : *.* /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
ERROR : No Destination Directory Specified.
i launched it right, but it can't see past the first parameter. Performing the same command using copy might have been running into the same problem.
How can I get ALL the robocopy parameters to get handed across to the new cmd instance?
p.s. my whole script is here: http://pastebin.com/xgpGJYmU : feel free to optimise it!
Upvotes: 2
Views: 1413
Reputation: 2427
Ok, so after stumbling about with this for ages I finally worked out that a character at the start of the destination had an ascii code less than zero. both filesystemobject and asp is funny like that and lets you have stupid scenarios like this. asp unicode implementation: you bastard!
it was there staring me in the face from the very beginning:
00:19: %comspec% /k robocopy \\qnap\qdownload\transmission\completed
\\pvr\e\tv\MythBusters Mythbusters.S11E03.Hail.Hijinx.HDTV.x264-FQM.mp4 /R:3 /W:10
a line break before \pvr\e .. etc I treated it as if it were a wrapping problem in the command prompt, but no a bit of "character by character" exploration of the strings revealed the problem.
In the end I was unable to cut a regex that could convert my wide bytes back to ascii, so had to do a letter-by-letter approach:
Function unicodeToAscii(sText)
Dim x, aAscii, ascval, l
l = len(sText)
If l = 0 Then Exit Function
redim aAscii(l)
For x = 1 To l
ascval = AscW(Mid(sText, x, 1))
If (ascval < 0) Then
ascval = 65536 + ascval ' http://support.microsoft.com/kb/272138
End If
aAscii(x) = chr(ascval)
Next
unicodeToAscii = join(aAscii,"")
End Function
which is a totally sucky hack.
anyay, problem not with robocopy or wsh, but with unicode file systems! solved.
p.s. here's the updated, optimised pastebin of the entire script: http://pastebin.com/s1XtzCGC
Upvotes: 1