Results 1 to 6 of 6

Thread: [Resolved] objFS copy Problems...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    [Resolved] objFS copy Problems...

    I'm using the following code:

    VB Code:
    1. Private Sub Copy_Folder(From_ As String, To_ As String)
    2.  
    3. If Len(Dir$(To_, vbDirectory)) > 0 Then
    4.        objFS.DeleteFolder To_
    5.        objFS.CreateFolder To_
    6.    Else
    7.        objFS.CreateFolder To_
    8. End If
    9.  
    10. objFS.CopyFolder From_, To_
    11.  
    12. 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:
    1. Private Sub Backup_Event()
    2. Dim Tmp_Dest As String
    3.  
    4. If ChkOverWrite.Value = 0 Then
    5.  
    6. Tmp_Dest = BackUpDirTxt.Text & "\BU (" & DriveLetter.Text & ") - " & Get_Date_Time
    7. Copy_Folder DriveLetter.Text & ":\", Tmp_Dest
    8.  
    9. Else
    10.  
    11. If ChkOverWrite.Value = 1 Then
    12.  
    13. Tmp_Dest = BackUpDirTxt.Text & "\BU (" & DriveLetter.Text & ")"
    14. Copy_Folder DriveLetter.Text & ":\", Tmp_Dest
    15.  
    16. End If
    17. End If
    18.  
    19. End Sub
    20.  
    21. Public Function Get_Date_Time()
    22. Dim sTime As SYSTEMTIME
    23. GetLocalTime sTime
    24.    
    25. Get_Date_Time = sTime.wYear & sTime.wMonth & sTime.wDay & sTime.wHour & sTime.wMinute & sTime.wSecond
    26.  
    27. 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:
    1. objFS.CopyFolder From_, To_
    but it doesn't make a difference.

    Thank you!
    Last edited by Slyke; Jul 26th, 2006 at 09:40 AM.

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: objFS copy Problems...

    ok, you get an error, but you don't say what line it's on.

    also, place
    VB Code:
    1. Debug.Print From_, To_
    before the .CopyFolder line and see what the values are

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: objFS copy Problems...

    From Debug.Print i get

    "K:\ D:\Backup\BU (K) - 200672623251"
    .....^ Should have a bigger space however.



    VB Code:
    1. Private Sub Copy_Folder(From_ As String, To_ As String)
    2.  
    3. If Len(Dir$(To_, vbDirectory)) > 0 Then
    4.        objFS.DeleteFolder To_
    5.        objFS.CreateFolder To_
    6.    Else
    7.        objFS.CreateFolder To_
    8. End If
    9.  
    10. [B]objFS.CopyFolder From_, To_ 'This is the line [/B]
    11.  
    12. 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:
    1. Dim objFS As New Scripting.FileSystemObject
    2. Dim objFolder As Scripting.Folder

    I have put at the declarations section

    I hope this can help you help me

    Thanks.
    Last edited by Slyke; Jul 26th, 2006 at 08:07 AM.

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: objFS copy Problems...

    ok. the first parameter for the fso.CopyFolder is wrong:
    VB Code:
    1. ' These are OK:
    2. objFS.CopyFolder "C:\MyFolder", "C:\DestFolder"
    3. objFS.CopyFolder "C:\MyFolder\*", "C:\DestFolder"
    4.  
    5. ' this isn't
    6. objFS.CopyFolder "C:\MyFolder\", "C:\DestFolder"
    so for your code you'll have to pass the * as well:
    VB Code:
    1. 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:
    1. If objFS.FolderExists(To_) Then

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    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.

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width