• FileCopy (VB6)

    Author
    Topic
    #452877

    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

    Viewing 0 reply threads
    Author
    Replies
    • #1119277

      Which line causes the error?

      • #1119278

        Morning Hans

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

        Causes the problem, but it looks ok to me!

        • #1119280

          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:

          ...
          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
          ...

          I assume that it is your intention to copy selected files from the archive folder to the main folder?

          • #1119283

            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

            • #1119285

              Kill only works with files.

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

              RmDir SrcFolder

            • #1119287

              Thanks Hans

              All works ok now..

            • #1120079

              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.

            • #1120092

              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.

            • #1120322

              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?

            • #1120329

              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

            • #1120330

              Sorry Hans, just a typo error.

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

            • #1120331

              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

            • #1120333

              Great! Glad you found it.

            • #1120334

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

            • #1120335

              No, I don’t think so, MkDir works fine if the path doesn’t end in a backslash .

    Viewing 0 reply threads
    Reply To: FileCopy (VB6)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: