How to copy file from one path to another path
Copying File
Collapse
X
-
Tags: None
-
ADD reference to your Project "Microsoft Scripting Runtime"Originally posted by sandeepkrnHow to copy file from one path to another path
Use FilesystemObjec t in Ur Project.
Check The Different Property & method of filesystemobjec t.
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? -
Another simpler (and perhaps better) way of doing it is simply:
This is the simplest way, but leaves out a lot of error-catching.Code:FileCopy "c:\a.txt", "c:\test\a.txt" // Copies file Kill "c:\a.txt" // Deletes original file
Comment
-
I think there r two Problems in this code.Originally posted by cbbibleboyAnother simpler (and perhaps better) way of doing it is simply:
This is the simplest way, but leaves out a lot of error-catching.Code:FileCopy "c:\a.txt", "c:\test\a.txt" // Copies file Kill "c:\a.txt" // Deletes original file
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 requiredComment
-
It is fairly simple to check whether the source/dest files exist before attempting the copy. It's well worth learning about FileSystemObjec t, as it provides much more functionality than the built-in commands. But it's not always necessary.Originally posted by SanjuMtrI 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
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?
Comment
-
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.Comment
Comment