By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Copying File

P: 1
How to copy file from one path to another path
Apr 28 '07 #1
Share this Question
Share on Google+
5 Replies


P: 47
How to copy file from one path to another path
ADD reference to your Project "Microsoft Scripting Runtime"
Use FilesystemObject in Ur Project.
Check The Different Property & method of filesystemobject.

U will get u r Ans.Good Luck.

1st U try find out the sol by yourself.if not possible I will give U the Solve in Details ok?
Apr 28 '07 #2

P: 29
Another simpler (and perhaps better) way of doing it is simply:

Expand|Select|Wrap|Line Numbers
  1. FileCopy "c:\a.txt", "c:\test\a.txt" // Copies file
  2. Kill "c:\a.txt" // Deletes original file
This is the simplest way, but leaves out a lot of error-catching.
Apr 28 '07 #3

P: 47
Another simpler (and perhaps better) way of doing it is simply:

Expand|Select|Wrap|Line Numbers
  1. FileCopy "c:\a.txt", "c:\test\a.txt" // Copies file
  2. Kill "c:\a.txt" // Deletes original file
This is the simplest way, but leaves out a lot of error-catching.
I think there r two Problems in this code.

1)U can't say whether the File Exist in specific Path or not.
if the file doesn't exist in specific Path then U will get a runtime error. for Both
Statement.
2)the requirement is to copy the file, not to move the file so the Kill statement is
not required
Apr 29 '07 #4

Expert 5K+
P: 8,434
I think there r two Problems in this code.

1)U can't say whether the File Exist in specific Path or not.
if the file doesn't exist in specific Path then U will get a runtime error. for Both
Statement.
2)the requirement is to copy the file, not to move the file so the Kill statement is
not required
It is fairly simple to check whether the source/dest files exist before attempting the copy. It's well worth learning about FileSystemObject, as it provides much more functionality than the built-in commands. But it's not always necessary.

Also, I think it was nice of cbbibleboy to throw in the extra code demonstrating how to zap the original file if required. However, it might have been nice to make a more prominent note about what/why, to avoid disasters.

Oh, one other thing I'm curious about. What's the idea with the "//"? It doesn't compile under VB6. Is it...
  • from a different (probably later) version of VB?
  • from a different language, and shouldn't really be there?
  • intended to prevent accidental execution?
  • other?
Apr 30 '07 #5

P: 29
Yeah, that was just the simplest fix. And the '//' was an accident. I write in C most of the time so it was just a habit.
Apr 30 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.