Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: FileCopy (VB6)

  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    FileCopy (VB6)

    Hello

    The following code is returning error 76 Path not found ?
    I don't understand why, the code looks good to me.....


    Private Sub cmdLoad_Click()

    Dim SrcFolder As String
    Dim MainFolder As String


    Dim N As Integer ' Number
    Dim fn As String ' FileName

    SrcFolder = "L:mmpdfArchive" & Me.txtEstArch.Text & ""
    MainFolder = "L:MMPDFConsoleFiles" & Me.txtEstArch.Text & ""

    For N = 0 To lstArchive.ListCount - 1
    If lstArchive.Selected(N) Then
    fn = lstArchive.List(N)
    End If

    FileCopy SrcFolder & lstArchive.List(N), MainFolder & fn

    Next N

    For N = 0 To lstArchive.ListCount - 1
    If lstArchive.Selected(N) Then
    Kill SrcFolder & lstArchive.List(N)
    End If
    Next N

    Me.MousePointer = vbDefault
    Unload Me

    Call Form1280Image.cmdList_Click
    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileCopy (VB6)

    Which line causes the error?

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileCopy (VB6)

    Morning Hans

    FileCopy SrcFolder & lstArchive.List(N), MainFolder & fn

    Causes the problem, but it looks ok to me!

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileCopy (VB6)

    I think that the FileCopy line should be within the If...End If block, so that the file is only copied if it is selected in the list box:
    <code>
    ...
    For N = 0 To lstArchive.ListCount - 1
    If lstArchive.Selected(N) Then
    fn = lstArchive.List(N)
    FileCopy SrcFolder & fn, MainFolder & fn
    End If
    Next N
    ...
    </code>
    I assume that it is your intention to copy selected files from the archive folder to the main folder?

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileCopy (VB6)

    Hans
    I solved it by creating the folder as below.
    I now need to delete the folder, the kill statement below deletes the files but leaves the folder, can you help with the kill statement?


    Private Sub cmdLoad_Click()

    If lstArchive.ListCount = 0 Then
    MsgBox "No Files To Select", vbInformation, "Information"
    Unload Me
    Exit Sub
    End If

    If lstArchive.SelCount = 0 Then
    MsgBox "No Archives Selected", vbInformation, "Information"
    Unload Me
    Exit Sub
    End If

    Dim fso As New FileSystemObject
    Dim SrcFolder As String
    Dim MainFolder As String

    Dim N As Integer ' Number
    Dim fn As String ' FileName

    SrcFolder = "L:mmpdfArchive" & Me.txtEstArch.Text & ""
    MainFolder = "L:mmpdfConsoleFiles" & Me.txtEstArch.Text & ""

    For N = 0 To lstArchive.ListCount - 1
    If lstArchive.Selected(N) Then
    fn = lstArchive.List(N)
    End If

    If Dir(MainFolder, vbDirectory) = "" Then
    MkDir MainFolder
    End If


    FileCopy SrcFolder & lstArchive.List(N), MainFolder & fn
    Next N

    For N = 0 To lstArchive.ListCount - 1
    If lstArchive.Selected(N) Then
    Kill SrcFolder & lstArchive.List(N)

    End If
    Next N

    Me.MousePointer = vbDefault
    Unload Me

    Call Form1280Image.cmdList_Click
    End Sub

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileCopy (VB6)

    Kill only works with files.

    To delete a folder, you can use RmDir (Rm stands for Remove):

    RmDir SrcFolder

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileCopy (VB6)

    Thanks Hans

    All works ok now..

  8. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileCopy (VB6)

    Hans

    A little glitch.
    When killing or RmDir the folder, there is a system "Thumbs.db" file still residing.
    I need to delete this file in order to remove the folder, as it is at the moment, a permission error occurs.
    I can bye pass the error with coding but that will only cloud the problem.
    The file really needs to be force deleted.
    Is there any way to do this?
    I did a quick Google which didn't really give me any solutions.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileCopy (VB6)

    I'd turn off creation of Thumbs.db files:

    - Start Windows Explorer.
    - Select Tools | Folder Options...
    - Activate the View tab.
    - Tick the check box "Do not cache thumbnails".
    - Click OK.

    Next, use Start | Search... to find all Thumbs.db files, then delete them.

    From then on, you shouldn't have the problem any more.

  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileCopy (VB6)

    Hi Hans

    Thanks for the solution.
    Although it is an option, I thought a programatic version would best suit the need.
    There are 22 machines and didn't really want to alter their defaults.

    I've been looking around and thought FileSystemObject would do the trick:
    I tried a couple of examples:

    fso.DeleteFolder "L:mmpdfconsolefilestemp", True
    or
    fso.DeleteFolder "L:mmpdfconsolefilestemp & ", True

    Which still gives me the path not found 76 error. !
    Any suggestions?

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileCopy (VB6)

    Error 76 would seem to indicate that there's an error in the specified path. Check the spelling very carefully.
    If a file is in use, I get Error 70 (Access denied).

    BTW, the line

    fso.DeleteFolder "L:mmpdfconsolefilestemp & ", True

    is not correct because you placed the & within the quotes. The backslash isn't necessary, but if you wish to include it, you'd use

    fso.DeleteFolder "L:mmpdfconsolefilestemp", True

  12. #12
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileCopy (VB6)

    Sorry Hans, just a typo error.

    I'll check the path to see if case sensitive.
    Thanks

  13. #13
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileCopy (VB6)

    Hans
    It seems I have solved it. Early on in the code, a "" was added to MainFolder and SrcFolder. This caused the error 76.
    By removing it and adding to the [FileCopy SrcFolder & "" & lstArchive.List(N), MainFolder & "" & fn] routine, it has cured the problem.
    Thanks again for your help.

    Private Sub cmdLoad_Click()

    If lstArchive.ListCount = 0 Then
    MsgBox "No Files To Select", vbInformation, "Information"
    Unload Me
    Exit Sub
    End If

    If lstArchive.SelCount = 0 Then
    MsgBox "No Archives Selected", vbInformation, "Information"
    Unload Me
    Exit Sub
    End If

    Dim fso As New FileSystemObject
    Dim SrcFolder As String
    Dim MainFolder As String

    Dim N As Integer ' Number
    Dim fn As String ' FileName

    SrcFolder = "L:mmpdfArchive" & Me.txtEstArch.Text
    MainFolder = "L:mmpdfConsoleFiles" & Me.txtEstArch.Text
    'ERROR CAUSED HERE WITH THE ""
    'SrcFolder = "L:mmpdfArchive" & Me.txtEstArch.Text & ""
    'MainFolder = "L:mmpdfConsoleFiles" & Me.txtEstArch.Text & ""

    For N = 0 To lstArchive.ListCount - 1
    If lstArchive.Selected(N) Then
    fn = lstArchive.List(N)
    End If

    If Dir(MainFolder, vbDirectory) = "" Then
    MkDir MainFolder
    End If
    '"" ADDED IN THE ROUTINE

    FileCopy SrcFolder & "" & lstArchive.List(N), MainFolder & "" & fn
    Next N

    'fso.DeleteFolder "L:MmpdfArchiveTemp", True
    fso.DeleteFolder SrcFolder, True
    Set fso = Nothing

    Me.MousePointer = vbDefault
    Unload Me

    Call Form1280Image.cmdList_Click
    End Sub

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: FileCopy (VB6)

    Great! Glad you found it.

  15. #15
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FileCopy (VB6)

    Just a finel point Hans (Late thought)
    Would I need to add a "" to the end of [MkDir MainFolder]
    ?

Page 1 of 2 12 LastLast

Posting Permissions

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