Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
tecknowledge1164
Starting Member
25 Posts |
Posted - 2008-02-15 : 10:20:56
|
I am trying to find a way to do something in a program written in VB6. There is a procedure to copy files from one location to another using the fso.CopyFile method. I have had a request to have an option to move the file instead of copying it. In programs that I work with using vb.NET, we can do this in order to trap exceptions since the IO.File.Copy method includes an option to overwrite existing files at the new location and the File.Move method does not, so any files left behind at the old location indicate exceptions. I have not been able to find anything in VB6 concerning MoveFile or how to trap exceptions in it. It does appear that the CopyFile does have the option to overwrite. If anyone knows a way to do this I would appreciate it. TIABob Thompson |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-02-15 : 10:28:45
|
Why don't you use fso.MoveFile()?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
tecknowledge1164
Starting Member
25 Posts |
Posted - 2008-02-15 : 10:52:05
|
With MoveFile, what happens when a file with the same name appears in the destination location? In .net an error occurs since the overwrite option is not available in File.Move and you need to trap for it. I'm not sure of the proper way to deal with an error like that in vb6 code. That is what I need to do. Thanks. |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-02-15 : 10:58:16
|
In VB6 also, the error is thrown and you can catch it using On Error mechanism. Although, I don't think there is any option to forcefully overwrite the file.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
tecknowledge1164
Starting Member
25 Posts |
Posted - 2008-02-15 : 11:11:26
|
It has been a while since I have written much vb6 code so I'm a little rusty. In .net I just use a try... catch block and let it go. I don't need to overwrite it since I am only concerned with the files that get left behind at the old location. So in vb6 is it something like "on error resume next"? Is there a specific error to look for? It looks like I am pretty close here. I appreciate your help and patience. |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-02-15 : 11:15:19
|
[code]Private Sub Form_Load()On Error GoTo Err:Dim fso As New FileSystemObjectfso.MoveFile "C:\1\test.txt", "C:\2\test.txt"Exit SubErr:If Err.Number = 58 Then 'File Exists MsgBox "File Already exists!", , "Error"Else MsgBox Err.Number & " - " & Err.DescriptionEnd IfEnd Sub[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
|
|
|