Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Archive Files (VB6)

    I've been working on the archiving section of my application.
    With trial and error, I've lost a few files, and wondered if anyone had any idea why my code doesn't work.
    I know I'm pretty close:

    <pre>Private Sub CmdArchiveJPG_Click()
    Dim SF As String ' Source Folder
    Dim AF As String ' Archive Folder
    Dim N As Integer ' Number
    Dim FN As String ' FileName
    Dim DP As String ' Default Path
    SF = "L:MMPDFImage"
    AF = "L:MMPDFArchive"
    For N = 0 To lstFiles.ListCount - 1
    If lstFiles.Selected(N) Then
    FN = lstFiles.List(N)
    DF = Left$(FN, Len(FN) - 3) & "IMA"
    X = Shell("ckwarepkzip.exe -a " & AF & DF & " " & SF & FN, vbMinimizedNoFocus)
    'Set fso = New FileSystemObject
    Debug.Print lstFiles.List(N)
    fso.DeleteFile SF & lstFiles.List(N)
    End If
    Next N
    MsgBox "Files Archived", , "Information"
    End Sub</pre>


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

    Re: Archive Files (VB6)

    Could it be the problem with long file names you mentioned in an earlier thread? If not, which files do you lose, can you discover a pattern?

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Archive Files (VB6)

    It appears you are defining a collection and then copying the first file to a zip file, deleting the file and then looking for the next item in the collection. This is problematic as the collection has just shrunk by one item.

    Can you reverse the loop direction so that the last file is attacked first?
    For N = lstFiles.ListCount - 1 To 0 Step -1

    Alternatively, I would have a look at the switches used in the shelled zip command. I would expect you can move the file rather than copy it if you found the right switch. I use Winzip and the command line component called wzzip which has a lot of flexibility in copying files to a zip archive.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

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

    Re: Archive Files (VB6)

    Thanks Andrew

    Hans
    I sorted the long file name issue and selectively chose the files to archive for testing purposes only.
    But what Andrew says kind of makes sense, the list decreases each time the next (N) has to be found.
    I think I will probably split the code to complete one operation first, then attempt to complete the second task after.

    Something like ( Forgive mistakes, on the fly ):::

    <pre>Dim SF As String ' Source Folder
    Dim AF As String ' Archive Folder
    Dim N As Integer ' Number
    Dim FN As String ' FileName
    Dim DP As String ' Default Path
    SF = "L:MMPDFImage"
    AF = "L:MMPDFArchive"
    For N = 0 To lstFiles.ListCount - 1
    If lstFiles.Selected(N) Then
    FN = lstFiles.List(N)
    DF = Left$(FN, Len(FN) - 3) & "IMA"
    X = Shell("ckwarepkzip.exe -a " & AF & DF & " " & SF & FN, vbMinimizedNoFocus)
    End If
    Next N
    End Sub</pre>



    <pre>For N = 0 To lstFiles.ListCount - 1 To 0 Step -1
    If lstFiles.Selected(N) Then
    FN = lstFiles.List(N)
    Set fso = New FileSystemObject
    fso.DeleteFile SF & lstFiles.List(N)
    End If
    Next N
    MsgBox "Files Archived", , "Information"
    End Sub</pre>


    I will have to test it first and see what happens, comments are welcome.

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

    Re: Archive Files (VB6)

    Andrew has probably hit the nail on the head. I think your code will work, but I can't test it because I don't have pkzip (and have no need for it at the moment.)

    Note: don't create a new FileSystemObject within the loop - you'll end up creating many instances. Do it once before entering the loop, then set the object to Nothing after the loop.

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

    Re: Archive Files (VB6)

    Like this ?

    Set fso = New FileSystemObject
    For N = 0 To lstFiles.ListCount - 1 To 0 Step -1
    If lstFiles.Selected(N)
    ThenFN = lstFiles.List(N)
    fso.DeleteFile SF & lstFiles.List(N)
    End If
    Next N
    MsgBox "Files Archived", , "Information"
    Set fso = Nothing
    End Sub

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

    Re: Archive Files (VB6)

    <img src=/S/yep.gif border=0 alt=yep width=15 height=15>

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

    Re: Archive Files (VB6)

    <img src=/S/wink.gif border=0 alt=wink width=15 height=15>

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

    Re: Archive Files (VB6)

    With the above code, is there a alternative switch to PKZIP which will zip all files selected into one file as opposed to individual as my does.
    I think I may have to move the shell statement out of the loop, but fear if I do this, only one of the files will be zipped ?

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

    Re: Archive Files (VB6)

    You would have to assemble the command line string in the loop, then call it after the loop. Something like:

    ...
    Dim strCommand As String
    ' Change to the source drive and folder
    ' So that we don't have to specify the path each time
    ChDrive "L"
    ChDir SF
    ' First part of command line
    strCommand = "ckwarepkzip.exe -a " & AF & "Archive.zip"
    ' Loop through list box items
    For N = 0 To lstFiles.ListCount - 1
    If lstFiles.Selected(N) Then
    ' Append file name to command line
    strCommand = strCommand & " " & lstFiles.List(N)
    End If
    ' Run command line
    X = Shell(strCommand, vbMinimizedNoFocus)
    Next N
    ...

    Notes:
    1. Replace "Archive.zip" by the appropriate name (it shouldn't be the same as the name of a .jpg, since you are zipping several into one file)
    2. If many .jpg's have been selected, you may run into a problem, since a command line has a maximum length of 127 characters.

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

    Re: Archive Files (VB6)

    Hans
    Since each Image has an ext of 01, 02 etc ie: 12345-01.jpg, 12345-02.jpg, I'm sure I can use the MkDir command to make a
    folder of the same first 5 Characters.

    I'm just adding code as we speak to create the named folder before running the shell command.
    That way I think there are sufficient switches with PKZIP to archive into the named folder.

    Using the following, I can extract the initial file name to create the folder :<pre>DF = Left$(FN, Len(FN) - 7)</pre>

    Then each file copied won't be duplicated.

    I'll let you know how I go on.

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

    Re: Archive Files (VB6)

    Close <img src=/S/mad.gif border=0 alt=mad width=15 height=15> We need a smiley for frustration !! (I'll get it soon)

    <pre>Private Sub CmdArchiveJPG_Click()
    Dim SF As String ' Source Folder
    Dim AF As String ' Archive Folder
    Dim N As Integer ' Number
    Dim i As Integer ' Number
    Dim FN As String ' FileName
    Dim FNA As String 'FileName Archived
    Dim DP As String ' Default Path
    Dim strFolderName As String


    SF = "L:MMPDFImage"
    AF = "L:MMPDFArchive"

    Set fso = New FileSystemObject

    For N = lstFiles.ListCount - 1 To 0 Step -1
    If lstFiles.Selected(N) Then
    FN = lstFiles.List(N)

    strFolderName = Left$(FN, Len(FN) - 7)
    If Dir(strFolderName, vbDirectory) = "" Then
    MsgBox "Creating Folder To Archive" & " " & FN & " Files"
    MkDir strFolderName
    End If

    DF = Left$(FN, Len(FN) - 3) & "IMA"
    x = Shell("ckwarepkzip.exe -a " & strFolderName & DF & " " & SF & FN, vbHide)
    End If
    Next N

    For i = lstFiles.ListCount - 1 To 0 Step -1
    If lstFiles.Selected(i) Then
    FNA = lstFiles.List(i)
    'fso.DeleteFile SF & FNA
    Debug.Print SF & FNA
    End If
    Next i
    MsgBox "Files Archived", , "Information"
    Set fso = Nothing
    End Sub</pre>


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

    Re: Archive Files (VB6)

    What is the question? <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    You have placed the creation of a new folder and the Shell to pkzip inside the loop again, so this will be done for each file separately. I thought you wanted to zip all selected images into one zip file?

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

    Re: Archive Files (VB6)

    Yes you're right again Hans, I also omitted the AF within the create folder section.

    strFolderName = AF & Left$(FN, Len(FN) - 7)

    I thought it would be correct to insert within the loop because FN isn't created until items from the list had been selected ie:

    <pre>For N = lstFiles.ListCount - 1 To 0 Step -1
    If lstFiles.Selected(N) Then
    FN = lstFiles.List(N)

    strFolderName = AF & Left$(FN, Len(FN) - 7)
    If Dir(strFolderName, vbDirectory) = "" Then
    MsgBox "Creating Folder To Archive" & " " & FN & " Files"
    MkDir strFolderName
    End If</pre>


    As it stands at the moment, it does create the folder but copies no files into it (thats something I suppose !)

    I did originally say to archive multiple files into one zip file, but thinking a little further, If I zip all the imagesinto one zip,
    I still have to zip the PDF file along with it from a different command.
    Putting them all in one folder makes better sense.

    Ideally from one command button, I would archive files from L:MMPDFImage & L:MMPDFEstPDF where both job No's match.
    But for now, One step at a time.

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

    Re: Archive Files (VB6)

    I think there is a backslash missing in strFolderName, try

    strFolderName = AF & Left$(FN, Len(FN) - 7) & ""

    This doesn't matter when you create the folder with MkDir, but you need it when concatenating strFolderName & DF in the command line for pkzip.

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
  •