CopyFile problem

Author Message
wmec

  • Total Posts : 157
  • Scores: 0
  • Reward points : 0
  • Joined: 8/5/2004
  • Location: China
  • Status: offline
CopyFile problem - Thursday, December 09, 2004 8:08 PM ( #1 )
Hi all,
I've had a problem when running this line:

filesystemobject.copyfile wrt_fl, "y:\archive"

where wrt_fl can just hold the value like "Y:\filename.txt" that represents an existing file and "Y:\archive" is also an existing folder. But I did have the run-time error - '424' and how to solve this?

Bst Rgds,
Edward
Thanks & Best Regards,

HuaMin Chen
nicksvbs

  • Total Posts : 26
  • Scores: 2
  • Reward points : 0
  • Joined: 6/28/2004
  • Location:
  • Status: offline
Re: CopyFile problem - Sunday, December 12, 2004 9:53 AM ( #2 )
Try this.
Set objFSO = CreateObject("Scripting.FileSystemObject")
wrt_fl = "y:\filename.txt"
objFSO.CopyFile wrt_fl, "y:\archive\"


Note the trailing backslash after "y:\archive\". It has to be there because it's a folder.
Protus

  • Total Posts : 23
  • Scores: 0
  • Reward points : 0
  • Joined: 11/22/2004
  • Location: Australia
  • Status: offline
Re: CopyFile problem - Sunday, December 12, 2004 1:21 PM ( #3 )
umm.... thats exactly the same as what he wrote nick..... =D

how about this:

DIM wrt_fl
wrt_fl = "y:\filename.txt"
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "CMD /C copy " & wrt_fl & " y:\archive"
set WshShell = nothing
msgBox "Script complete."

it should work, and its simple. If you want something that is a little more functional, i could write it for you if you'd like :)
nicksvbs

  • Total Posts : 26
  • Scores: 2
  • Reward points : 0
  • Joined: 6/28/2004
  • Location:
  • Status: offline
Re: CopyFile problem - Sunday, December 12, 2004 5:17 PM ( #4 )
ummm... Why don't you look again, more carefully, at exactly what I did write, Protus? You'll see that it's NOT the same. His error 424 is due to his "filesystemobject" not being instantiated with a statement like this: Set filesystemobject = CreateObject("Scripting.FileSystemObject"). I just used objFSO as the reference name in my script instead. After that's fixed he also needs to add the trailing backslash to the target folder or else the FSO will think that's supposed to be the target filename instead of a folder and will result in an error. And why would you possibly use the shell copy command when the FileSystemObject supplies a method to do just that? He might as well just use a batch file.
copy y:\filename.txt y:\archive

One line. Done!

Anyway, hope this clarifies my previous post.
Protus

  • Total Posts : 23
  • Scores: 0
  • Reward points : 0
  • Joined: 11/22/2004
  • Location: Australia
  • Status: offline
Re: CopyFile problem - Sunday, December 12, 2004 9:25 PM ( #5 )
umm.... i think we can safely say that if he was using FSO then he would of already set it, as well as setting the wrt_fl. Just because he didn't write it in the post doesnt mean he didn't have it. He most likely wrote the part of cose which he thought had the problem (unless he has no idea and just copied and pasted that line from somewhere else on this forum in which case i take back everything i say in this forum if thats true). The only thing i saw different was your code is you have a backslash, which is unneeded. That code copies the variable, which a batch file does not, but why the hell not use a batch file? Alot faster. Why not just run it through CMD? FSO isn't even needed in this case, you simply over complicated something so simple.

Oh and by the way, instantiated? ROFL, it means to represent. +D
nicksvbs

  • Total Posts : 26
  • Scores: 2
  • Reward points : 0
  • Joined: 6/28/2004
  • Location:
  • Status: offline
Re: CopyFile problem - Monday, December 13, 2004 8:05 AM ( #6 )
For the last time, if you try my 3 line script from my original post, it will work. Remove the trailing backslash from the target folder and it WILL fail. Period.
From the MS Win2000 Scripting Guide:

http://www.microsoft.com/resources/documentation/windows/2000/server/scriptguide/en-us/sas_scr_ytql.mspx
quote:
When specifying the destination folder, it is important to include the trailing backslash (for example, D:\Archive\). If the backslash is there, CopyFile will copy the file into the Archive folder. If the backslash is not there, CopyFile will try to create a new file named D:\Archive. If the folder D:\Archive already exists, a "Permission denied error" will be generated, and the copy procedure will fail.

Do it however you want Protus, I don't care. As for overcomplicating things, that's you not me. My script snippet was quiet simple and easy to understand. As for my use of the term "instantiate", if a word provides you with comic relief, glad I could help.

wmec, I hope you get something out of this thread 'cause I'm done with it.

Best regards,
Nick
Protus

  • Total Posts : 23
  • Scores: 0
  • Reward points : 0
  • Joined: 11/22/2004
  • Location: Australia
  • Status: offline
Re: CopyFile problem - Monday, December 13, 2004 6:30 PM ( #7 )
=D

Hey admins when are you gonna fix up the old posts? I had nearly 30 and i just helped some dude hq_bomb or something, i dunno if he got the post.

After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.
Jump to:

Current active users
There are 0 members and 1 guests.
Icon Legend and Permission
  • 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
  • Read Message
  • Post New Thread
  • Reply to message
  • Post New Poll
  • Submit Vote
  • Post reward post
  • Delete my own posts
  • Delete my own threads
  • Rate post

© 2000-2009 ASPPlayground.NET Forum Version 3.6