Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax problem driving me crazy!

Status
Not open for further replies.

cbsarge

IS-IT--Management
Jun 20, 2001
219
US
I have the following script which currently doesn't work. I'm pretty sure it's just a matter of getting the syntax correct for the wshshell.run line but, haven't been able to figure it out yet. Here is the current script:
Code:
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.InitialDir = "C:\"
intResult = objDialog.ShowOpen
If intResult = 0 Then
    MsgBox "You didn't select a file."
	Wscript.Quit
Else
End If
Set objShellApp = CreateObject("Shell.Application") 
Set objMyComputer = objShellApp.NameSpace (&H11&)
Set objFolder = objShellApp.BrowseForFolder (0, "Browse to the desired folder", 0)
If objFolder = null Then
	MsgBox "You didn't select a folder."
	Wscript.Quit	
Else
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run ("cmd /c xcopy /s /c /d /e /h /i /r /k /y "& objDialog.FileName &" "& objFolder.self.Path &" "),0,True
Wscript.Echo objDialog.FileName & " was copied to " & objFolder.Self.Path
End If

Thanks for your help!

[!]The AutoSavers![/!] [2thumbsup]
 
[1] I think you have had been advised to put quotes around path which possibly contains whitespace in your other threads, have you not?

[2] In your gui initiated for the "source", it accepts only file as source, hence, these switches (/s /e) are not reasoning well. They should be taken out. Also the switch /i is never meant for anything again in the way the functionality is scripted. It should be taken out.

[3] You can control the return of .run method before announcing copy is actually done.
[tt]
'etc etc same
Else
Set WshShell = WScript.CreateObject("WScript.Shell")
[blue]iret=[/blue]WshShell.Run ("cmd /c xcopy [highlight]/c/d/h/r/k/y[/highlight] " & [red]chr(34) & [/red]objDialog.FileName [red]& chr(34)[/red] & " " & [red]chr(34) &[/red] objFolder.self.Path [red]& chr(34)[/red],0,True)
if iret=0 then
Wscript.Echo objDialog.FileName & " was copied to " & objFolder.Self.Path
else
'WScript.Echo "Copy is not successful for some reason."
end if
End If
[/tt]
 
Lol - it's always the silly things that hang me up!

I neglected to use the chr(34) to designate where spaces should be in the command string. Putting those in made it work.

Thanks tsuji!

[!]The AutoSavers![/!] [2thumbsup]
 
The main thing is the switches more than anything else, though the quotes are necessary if you want the script consistently perform. If you have /s/e, it is disaster.
 
Yup - the original line was in another script I wrote and it including some directories - not just a file. I'm going to continue to work on the script to allow for selecting a file or directory as the copy source so I'll want the /s /e.

[!]The AutoSavers![/!] [2thumbsup]
 
I repeat, /s/e is a disaster for source being a file. Want may you, that is another matter for another script.
 
Thanks again tsuji. I have removed those flags from the current script.
Code:
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.InitialDir = "C:\"
intResult = objDialog.ShowOpen
If intResult = 0 Then
    MsgBox "You didn't select a file."
	Wscript.Quit
Else
End If
Set objShellApp = CreateObject("Shell.Application") 
Set objMyComputer = objShellApp.NameSpace (&H11&)
Set objFolder = objShellApp.BrowseForFolder (0, "Browse to the desired folder", 0)
If objFolder = null Then
	MsgBox "You didn't select a folder."
	Wscript.Quit	
Else
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run ("cmd /c xcopy /c/d/h/r/k/y " & chr(34) & objDialog.FileName & chr(34)  & " " & chr(34) & objFolder.self.Path & chr(34)),0,True
Wscript.Echo objDialog.FileName & " was copied to " & objFolder.Self.Path
End If

[!]The AutoSavers![/!] [2thumbsup]
 
You still need to control the return value (iret) to be sure the copy operation is successful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top