Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


issue with robocopy

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,59314
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> issue with robocopy
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 issue with robocopy - 4/20/2008 1:24:19 PM   
  associates

 

Posts: 10
Score: 0
Joined: 2/27/2008
Status: offline
Hi,

I was trying to copy a file from one folder to another folder on XP Pro. I would like to use VB script to do this. However, i'm getting the following error message

"The system cannot find the file specified"

Here is the code


Set WshShell = WScript.CreateObject("WScript.Shell")

strWorkingDir = "%HOMEPATH%"

strText = "C:" & WSHShell.ExpandEnvironmentStrings(strWorkingDir) & "\Application Data\Microsoft\Templates"
strCmd = "robocopy C:\Documents and Settings\user1\My Documents\sections.dot " & strText
wscript.echo(strCmd)
Dim oRobo: set oRobo = WshShell.Exec(strCmd)

WScript.Quit

However the file hasn't been copied across. Would anyone been able to point out in the codes where i made mistake please?

Thank you in advance


< Message edited by associates -- 4/20/2008 2:11:59 PM >
 
 
Post #: 1
 
 RE: issue with robocopy - 4/20/2008 2:59:24 PM   
  dm_4ever


Posts: 2433
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
The problem is with the spaces....this is a very very very common question and a search should have shown you how to handle this.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to associates)
 
 
Post #: 2
 
 RE: issue with robocopy - 4/20/2008 6:12:27 PM   
  associates

 

Posts: 10
Score: 0
Joined: 2/27/2008
Status: offline
Thank you dm_4ever for your reply.

I have realised that the code was wrong but still could not figure out where/which part in the following that has problem with spaces.

strText = "C:" & WSHShell.ExpandEnvironmentStrings(strWorkingDir) & "\Application Data\Microsoft\Templates"
strCmd = "robocopy C:\Documents and Settings\user1\My Documents " & strText & " sections.dot" 
wscript.echo(strCmd)
Dim oRobo: set oRobo = WshShell.Exec(strCmd)

When i tried putting the full path in the DOS command line, it actually worked.

I have tried the search but still didn't find any that might help solve the problem. I must've used the inaccurate word in the search. Would you mind pointing me to where i can get more relevant info.

Thank you for your patience  

(in reply to associates)
 
 
Post #: 3
 
 RE: issue with robocopy - 4/20/2008 11:19:55 PM   
  mbouchard


Posts: 1863
Score: 14
Joined: 5/15/2003
From: USA
Status: online
the issue is with this line:

strCmd = "robocopy C:\Documents and Settings\user1\My Documents " & strText & " sections.dot" 

Basically, Robocopy is having trouble with the path and is probably seeing the above truncated.  One way to see this would be to use .RUN in place of EXEC.

Try the below and see if it give you a message.
WshShell.Run "cmd /K " & strCmd

With that said.  Try something like this

strCmd = """" & "robocopy C:\Documents and Settings\user1\My Documents " & """" &  """" & strText & " sections.dot"  & """"

Do a search for chr(34) at lease that is what I think the chr for " is.  You can look in the WSH docs for more info on the character maps.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to associates)
 
 
Post #: 4
 
 RE: issue with robocopy - 4/27/2008 3:44:00 PM   
  associates

 

Posts: 10
Score: 0
Joined: 2/27/2008
Status: offline
Thank you Mike for your reply.

I'm still encountering error when running the following script.


Set WshShell = WScript.CreateObject("WScript.Shell")

strWorkingDir = "%HOMEPATH%"
objSource = "C:\Documents and Settings\user1\My Documents"
objDest = "C:" & WshShell.ExpandEnvironmentStrings(strWorkingDir) & "\Application Data\Microsoft\Templates"
strCmd = "robocopy " & Chr(34) & objSource & Chr(34) & " " & Chr(34) & objDest & Chr(34) & " " & Chr(34) & " sections.dot"

nReturn = WshShell.Run(strCmd, 0, True)
WScript.Echo nReturn

The result is nReturn = 0

I have tried
strCmd = "robocopy " & Chr(34) & objSource & Chr(34) & " " & Chr(34) & objDest & Chr(34) & "   sections.dot"

None really works. I saw similar ones when performing search in the forum but haven't encountered the one that actually copies one file from one place to another.

Your help is greatly appreciated.

Thank you in advance

(in reply to mbouchard)
 
 
Post #: 5
 
 RE: issue with robocopy - 4/28/2008 12:15:08 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
First, figure out how to build the command that you want at the command line. Do this before you even try writing the VBS command. Once you know exactly what the right command looks like at the command line then you can start figuring out how to build it in VBS.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to associates)
 
 
Post #: 6
 
 RE: issue with robocopy - 4/28/2008 12:16:51 AM   
  mbouchard


Posts: 1863
Score: 14
Joined: 5/15/2003
From: USA
Status: online
Try this, take the commnd and manually type it into a CMD window.  Once you have that working, take it and do this in your script

Wscript.Echo strCMD & vbcr & "Robocopy Known Good Command Line Here"

And see what you get and compare the lines.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to associates)
 
 
Post #: 7
 
 RE: issue with robocopy - 4/28/2008 11:37:22 AM   
  associates

 

Posts: 10
Score: 0
Joined: 2/27/2008
Status: offline
Thank you Mike and Ebgreen for your replies.

Yes, it works now.


strCmd = "robocopy " & Chr(34) & objSource & Chr(34) & " " & Chr(34) & objDest & Chr(34) & " " & Chr(34) & "sections.dot"

It was that close (the problem with the space again).

Thank you for being such great helpful.



(in reply to mbouchard)
 
 
Post #: 8
 
 RE: issue with robocopy - 4/28/2008 7:09:12 PM   
  ginolard


Posts: 1024
Score: 21
Joined: 8/10/2005
Status: offline
My favourite issue with RoboCopy is the default number of times it will attempt to try and copy a file.

/R:n :: number of Retries on failed copies: default 1 million.
/W:n :: Wait time between retries: default is 30 seconds.

Marvellous.  So, if it fails to copy a file, it will try again for you for about, ooh, 6 days ;)

_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to associates)
 
 
Post #: 9
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> issue with robocopy Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts