HKFuey
asked on
VB6 copy and move
I have some VB6 code that copies files over the network.
I want to use this to copy SQL backup files which are in this format: - Database_backup_2009063012 00.bak
Does anyone know of a simple solution that allows me to copy all the items in a folder to another and then move the copied files so they are not re-copied next time the program is run?
I want to use this to copy SQL backup files which are in this format: - Database_backup_2009063012
Does anyone know of a simple solution that allows me to copy all the items in a folder to another and then move the copied files so they are not re-copied next time the program is run?
Option Explicit
Dim NetFile As String
Dim HDFile As String
Sub main(HDFile As String, NetFile As String)
On Error GoTo Errtrap
FileCopy NetFile, HDFile
Exit Sub
Errtrap:
Select Case Err
Case 91 ' not set
Resume Next
Case 53 ' file not found
Resume Next
Case Else
MsgBox Err & " " & Err.Description
End
Exit Sub
End Select
End Sub
Private Sub Form_Load()
NetFile = "\\files\users\andy\temp\Test.bak"
HDFile = "c:\temp\test.bak"
main HDFile, NetFile
End
End Sub
ASKER
I have already looked at that here: -
http://articles.techrepubl ic.com.com /5100-1087 8_11-10500 78.html (posted by Angelll)
If I put this in my code 'Dim fso As New FileSystemObject' I get an error 'User Type not defined'
http://articles.techrepubl
If I put this in my code 'Dim fso As New FileSystemObject' I get an error 'User Type not defined'
ASKER
OK got a bit further, I added the reference Microsoft Scripting Runtime
ASKER
I can get the FilesystemObject to work, does anyone know the syntax to copy/move all the files in a folder?
ASKER
OK I've done it, code below
Option Explicit
Dim MovFile
Dim NetFile As String
Dim HDFile As String
Sub main(HDFile As String, NetFile As String)
Dim fso As New FileSystemObject
On Error GoTo Errtrap
fso.CopyFile NetFile, HDFile
fso.MoveFile NetFile, MovFile
Exit Sub
Errtrap:
Select Case Err
Case 91 ' not set
Resume Next
Case 53 ' file not found
Resume Next
Case Else
MsgBox Err & " " & Err.Description
End
Exit Sub
End Select
End Sub
Private Sub Form_Load()
NetFile = "\\files\users\andy\temp\*.*"
HDFile = "c:\temp2\"
MovFile = "\\files\users\andy\temp\Mov\"
main HDFile, NetFile
End
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help!
http://msdn.microsoft.com/en-us/library/6kxy1a51%28VS.85%29.aspx