Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

For kamall Q.10151245 Combining files

Posted on 1999-07-31
6
Medium Priority
?
170 Views
Last Modified: 2010-04-30
For your assistance with Q.10151245
0
Comment
Question by:darinw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 1528686
<ameba waiting for free lunch (code)>
kamall wrote:
>I will post it when the conflict ends up and I get awarded.
0
 
LVL 7

Expert Comment

by:kamall
ID: 1528687
darinw,
Thank you very much for your efforts. I greatly appreciate them.
Although I will accept the points for your Q., I *COMPLETELY* disagree with the concept. I wanted to *PROVE* that what I said was the truth and that vienna was *LYING*.
I provided the *EXACT* solution for vienna's Q., and it was *COMPLETELY* unfair that he claims things that were *ENTIRELY FALSE*, rejecting the answer and refunding his points. I would never accept this if I was in your position. I even would like to see such people to be treated appropriately at EE.
Anyway, I thank you again.

Thank you very much MikeP, ameba, mark2150, and vettranger for your comments and your support at the mentioned Q.
I am posting the code in an answer below.

Best regards to all.
0
 
LVL 7

Expert Comment

by:kamall
ID: 1528688
I also would like to post my last comment for this coflict, appeared in the mentioned question (Q.10151245) to clarify the case:

darinw,
       Thank you for the comment and for testing the project.
       Now let me clarify the following:

       1. If you read the question carefully, you will see that vienna wanted the code that will package multiple files into one file and then being able to
       get back any of the original files individually.
       Question - Is this accomplished in my project?
       Answer: YES.

       2. He said (also in the q.):
       >> Yes, It does resemble, in part, the functionality's of ZIP, however, I do not know if I can use it, (license issue) or how I would even make
       these calls from Visual Basic.
       I do not have to compress anything. I just need these files combined into 1 with the power to call individual files when need.
       - Again, my project does this functionality exactly.

       3. When mark2150 (the first answer) proposed PKZIP, vienna replied with:
       >> I can not use PKZIP simply because it is not free and I can not redistribute it.
       Question - What is the difference between PKZIP's functionality and my project functionality except the compression issue which he didn't need?

       Answer: Nothing

       4. Most importantly, we ended up with the following claims by vienna for which he rejected my answer (the project):
       >> however I must reject your proposed answer for the following reasons:
       The example provided to me only works with ascii based files.
       Question - Is this true?
       Answer: ABSOLUTELY NOT

       >> It appears.... . Therefore, I can not properly call the extraction of a particular file.
       Question - Is this true?
       Answer: ABSOLUTELY NOT

       Now tell me darinw, what is TRUE in vienna's claims?????

       SUMMARY:
       He wanted code that can:
       - Make a package - Done 100%.
       - Extract any individual file from the package - Done 100%
       - Works with all types of files - Done 100%

       Would like to see your comments darinw!
       Also would like to see other expert's comments for my current comment.

       Thank you and best regards.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Accepted Solution

by:
kamall earned 800 total points
ID: 1528689
'***************** File Packaging and Extraction Utility *******************
'***************** Copyright © 1999 - Kamal A. Mehdi *******************
'***************** E-Mail: kamal@amphipolis.ee.auth.gr *******************
'
'*** Note: Please note that to use this code in your own applications,  ***
'*** you MUST obtain a WRITTEN PERMISSION from the author (above)  ***
'
Dim Chunk1 As String * 10000
Dim Chunk2 As String * 5000
Dim Chunk3 As String * 1000
Dim Chunk4 As String * 1
Dim FileArray() As String

Private Sub Command1_Click()
   
    'Make the package
   
    'Open package file
    Open File1.Path & "\" & "Package.fil" For Binary Access Write As #1
    'Open package log file
    Open File1.Path & "\" & "Package.log" For Output As #3
   
    'Recurse through all File1 files and pack them
    For x = 0 To File1.ListCount - 1
        RemainingBytes = FileLen(File1.Path & "\" & File1.List(x))
        'Open the source file
        Open File1.Path & "\" & File1.List(x) For Binary Access Read As #2
            'Start data transfer with variable chunk sizes
            Do
                If RemainingBytes >= 10000 Then
                    Get #2, , Chunk1
                    Put #1, , Chunk1
                    RemainingBytes = RemainingBytes - 10000
                    DoEvents
                ElseIf RemainingBytes >= 5000 Then
                    Get #2, , Chunk2
                    Put #1, , Chunk2
                    RemainingBytes = RemainingBytes - 5000
                    DoEvents
                ElseIf RemainingBytes >= 1000 Then
                    Get #2, , Chunk3
                    Put #1, , Chunk3
                    RemainingBytes = RemainingBytes - 1000
                    DoEvents
                ElseIf RemainingBytes >= 1 Then
                    Get #2, , Chunk4
                    Put #1, , Chunk4
                    RemainingBytes = RemainingBytes - 1
                End If
            Loop Until RemainingBytes = 0
        Close 2
        DoEvents
        'Write data to the log file
        If x = 0 Then Write #3, "Files=" & File1.ListCount
        Write #3, File1.List(x); FileLen(File1.Path & "\" & File1.List(x))
    Next
    Close 1
    Close 3
    DoEvents
    MsgBox "Package created successfully.", vbInformation
   
End Sub

Private Sub Command2_Click()

    Dim FilePosition As Long
    Dim FileSize As Long
   
    'Check if no file was selected from the list
    If List1.ListIndex < 0 Then
        MsgBox "Please select a file to extract.", vbInformation
        Exit Sub
    End If
       
    'Get file name to extrect
    FileToExtract = FileArray(List1.ListIndex, 1)

    'Specify the package file name
    MyPackage = File1.Path & "\Package.fil"
   
    'Get file position (within the package)
    If List1.ListIndex > 0 Then
        For x = 0 To List1.ListIndex - 1
            FilePosition = FilePosition + Val(FileArray(x, 2))
        Next
        FilePosition = FilePosition + 1
    Else
        FilePosition = 0
    End If
   
    'Get file size
    FileSize = Val(FileArray(List1.ListIndex, 2))
   
    DestFile = File1.Path & "\" & FileToExtract
   
    'Ckeck if file exists
    If Dir(DestFile) <> "" Then
        MsgBox "File already exist, can not extract.", vbInformation
        Exit Sub
    End If
   
    'Start extracting
    Open MyPackage For Binary Access Read As #1
    Open DestFile For Binary Access Write As #2
        If FilePosition > 0 Then Seek #1, FilePosition
        RemainingBytes = FileSize
        Do
            If RemainingBytes >= 10000 Then
                Get #1, , Chunk1
                Put #2, , Chunk1
                RemainingBytes = RemainingBytes - 10000
                DoEvents
            ElseIf RemainingBytes >= 5000 Then
                Get #1, , Chunk2
                Put #2, , Chunk2
                RemainingBytes = RemainingBytes - 5000
                DoEvents
            ElseIf RemainingBytes >= 1000 Then
                Get #1, , Chunk3
                Put #2, , Chunk3
                RemainingBytes = RemainingBytes - 1000
                DoEvents
            ElseIf RemainingBytes >= 1 Then
                Get #1, , Chunk4
                Put #2, , Chunk4
                RemainingBytes = RemainingBytes - 1
            End If
        Loop Until RemainingBytes = 0
    Close 1
    Close 2
    DoEvents
    MsgBox "File extracted successfully."
   
End Sub

Private Sub Dir1_Change()
   
    File1.Path = Dir1.Path
   
End Sub

Private Sub Drive1_Change()
   
    Dir1.Path = Drive1.Drive
   
End Sub

Private Sub File1_Click()
   
    'Get data from the log file if a package file is selected and show
    'the files in the list box
    If File1.filename = "Package.fil" Then
            Open File1.Path & "\" & "Package.log" For Input As #1
                Input #1, x0
                NumOfFiles = Right(x0, Len(x0) - 6)
                ReDim FileArray(NumOfFiles - 1, 1 To 2)
                Do While Not EOF(1)
                    Input #1, X1
                    Input #1, X2
                    List1.AddItem X1 & "  -  " & X2 & " bytes"
                    FileArray(z1, 1) = X1
                    FileArray(z1, 2) = X2
                    z1 = z1 + 1
                Loop
            Close 1
    Else
        List1.Clear
    End If
   
End Sub


0
 
LVL 3

Author Comment

by:darinw
ID: 1528690
I understand your position. I will tell my boss about the question to bring her into the loop too.

darinw
0
 
LVL 7

Expert Comment

by:kamall
ID: 1528691
Thanks darinw.
I appreciate your help.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question