[Resolved] objFS copy Problems...
I'm using the following code:
VB Code:
Private Sub Copy_Folder(From_ As String, To_ As String)
If Len(Dir$(To_, vbDirectory)) > 0 Then
objFS.DeleteFolder To_
objFS.CreateFolder To_
Else
objFS.CreateFolder To_
End If
objFS.CopyFolder From_, To_
End Sub
I'm trying to copy all the contents off my K drive into D:\Backup.
The program i'm trying to create automatically backs up my USB key apon being plugged in (that bit i'm still working on), for now i'm trying to just get it to copy the contents of the USB device!
The error i get is:
Run-time Error '5':
Invalid procedure call or argument
I have code that creates another folder inside the backup folder (with the date and time inside the name), but i don't think that that is causing the problem.
VB Code:
Private Sub Backup_Event()
Dim Tmp_Dest As String
If ChkOverWrite.Value = 0 Then
Tmp_Dest = BackUpDirTxt.Text & "\BU (" & DriveLetter.Text & ") - " & Get_Date_Time
Copy_Folder DriveLetter.Text & ":\", Tmp_Dest
Else
If ChkOverWrite.Value = 1 Then
Tmp_Dest = BackUpDirTxt.Text & "\BU (" & DriveLetter.Text & ")"
Copy_Folder DriveLetter.Text & ":\", Tmp_Dest
End If
End If
End Sub
Public Function Get_Date_Time()
Dim sTime As SYSTEMTIME
GetLocalTime sTime
Get_Date_Time = sTime.wYear & sTime.wMonth & sTime.wDay & sTime.wHour & sTime.wMinute & sTime.wSecond
End Function
Please note that the overwrite checkbox isn't used for overwriting. It detmines whether a new folder should be made with the date & time, or if it just saves to the one folder each time.
I have tried putting a True or False on the end of
VB Code:
objFS.CopyFolder From_, To_
but it doesn't make a difference.
Thank you!
Re: objFS copy Problems...
ok, you get an error, but you don't say what line it's on.
also, placebefore the .CopyFolder line and see what the values are
Re: objFS copy Problems...
From Debug.Print i get
"K:\ D:\Backup\BU (K) - 200672623251"
.....^ Should have a bigger space however.
VB Code:
Private Sub Copy_Folder(From_ As String, To_ As String)
If Len(Dir$(To_, vbDirectory)) > 0 Then
objFS.DeleteFolder To_
objFS.CreateFolder To_
Else
objFS.CreateFolder To_
End If
[B]objFS.CopyFolder From_, To_ 'This is the line [/B]
End Sub
I don't know the reason for this error? Isn't it usually for when you don't call something correctly? The parameters are correct arn't they?
VB Code:
Dim objFS As New Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
I have put at the declarations section
I hope this can help you help me :p
Thanks.
Re: objFS copy Problems...
ok. the first parameter for the fso.CopyFolder is wrong:
VB Code:
' These are OK:
objFS.CopyFolder "C:\MyFolder", "C:\DestFolder"
objFS.CopyFolder "C:\MyFolder\*", "C:\DestFolder"
' this isn't
objFS.CopyFolder "C:\MyFolder\", "C:\DestFolder"
so for your code you'll have to pass the * as well:
VB Code:
Copy_Folder DriveLetter.Text & "[B]:\*[/B]", Tmp_Dest
also, since you're already using FSO, you might as well use it to check if the folder exists:
VB Code:
If objFS.FolderExists(To_) Then
Re: objFS copy Problems...
Yes, thank you this fixed the problem.
Just a quick question before i paste [Resolved]...
Is ther anyway to stop my program from freesing while this happens? & is it possbile to have a progress bar involved too?
Thank you.
Re: objFS copy Problems...
Quote:
Originally Posted by Slyke
Is ther anyway to stop my program from freesing while this happens? & is it possbile to have a progress bar involved too?
yes, but you need a completely different approach using SHFileOperation API - check out this example at VBnet