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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with CopyFile 1

Status
Not open for further replies.

EriRobert

MIS
May 9, 2003
114
GB
Hi

I'm a beginner with VB script and am trying to write a simple one to copy a file

The full script:
------
Dim strOldPath
Dim strNewPath
Dim FSO
strOldPath = "C:\Program Files\PhonApp\PhonApp.mdb"
strNewPath = "\\Se002\1Datas\Phon\Release\PhonApp.mdb"
Set FSO = CreateObject("Scripting.FileSystemObject")
Do While FSO.FileExists(Left(strOldPath, Len(strOldPath) - 3) & "ldb") = True
'As long as an ldb file exists, someone is in the database, so just do nothing until it goes.
Loop
Set wshshell = WScript.CreateObject("WScript.Shell")
FSO.CopyFile strNewPath, strOldPath, True
wshshell.Run strOldPath
-----

When I run this script I get the error message:

-----
Script \\se002\1Datas\Phon\Release/UpdateFrontEnd.vbs
LIne: 19
Char: 1
Error: The system cannot find the file specified
Code: 80070002
Source: (null)
-----

I'm imagining that the crash is on the line

FSO.CopyFile strNewPath, strOldPath, True

as it will expand to

FSO.CopyFile \\Se002\1Datas\Phon\Release\PhonApp.mdb, C:\Program Files\PhonApp.mdb, True

and the space in 'Program Files' confuses it. When I try it with a folder without a space its OK.

I've tried defining it as

strOldPath = """C:\Program Files\PhonApp\PhonApp.mdb"""
and
strOldPath = "'C:\Program Files\PhonApp\PhonApp.mdb'"

but it just comes up with different errors:

Any ideas?
 
I think the problem is here:
wshshell.Run strOldPath
Try something like this:
wshshell.Run Chr(34) & strOldPath & Chr(34)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello EriRobert,

[1] Your copyfile copies the file at unc \\Se002\... to the c:\... Not the reverse. Is that what you want? If not, reverse the order of the argument to .copyfile.
[2] Why the do while loop? You're testing the existence of one file.
[3] The run file correction as per PHV's posting.

regards - tsuji
 
PHV

That was the problem. Thank you.

Take a star

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top