• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Extract a specific file from a .zip file & search for a string if it exists in the extracted file.

inddon

Member
Hello There,

I would like to know the VBA code for the following requirement:
Following parameters passed to the Function:

1. The name of the .zip file (complete folder path including zip file name: C:\FolderFile.zip)
2. Name of the sub directory in the .zip (where the file to be extracted is located --> Folder3)
3. Name of the file to be extracted from the folder (from step 2 --> folder3 Myfile3.csv)
4. String value to be searched in the extracted file (in Step 3 --> "Don")

A Function which would return True if the string "Don" is found else False. At the end of the execution delete the zip file

I have attached a sample zip file for your reference.

Looking forward to hearing from you.

Regards,
Don
 

Attachments

  • Folders.zip
    517 bytes · Views: 5
Hi !​
Microsoft Shell Controls And Automation reference must be activated …​
Code:
Function ZipETFK(ZP$, ZF$, EP$, EF$, T$) As Boolean
        Bill$ = ZP & "\" & ZF:  If Dir(Bill) = "" Then Exit Function
    With New Shell
        .Namespace(ZP).CopyHere .Namespace(Bill).Items.Item(IIf(EP > "", EP & "\" & EF, EF)), 16
    End With
        Kill Bill
        Bill = ZP & "\" & EF:  If Dir(Bill) = "" Then Exit Function
        F% = FreeFile
        Open Bill For Input As #F
        ZipETFK = InStr(Input(LOF(F), #F), T)
        Close #F
        Kill Bill
End Function
Do you like it ? So thanks to click on bottom right Like !
 
Hi,

For me, I have never seen before parameters being defined as (ZP$, ZF$, EP$, EF$, T$) with $ sign. Overall the whole function is something new learning experience. Thank you for taking the time to write the Function. What is the benefit of defining parameters in such a manner than the traditionla way (eg. pFileName as String v/s ZF$)?

I forgot to mention in my post an additional point: how to read the modified datetime of that file in the .zip. I will create a different post.

Regards,
Don
 
Last edited by a moderator:
That's just a legacy from VBA grandfather : the BASIC …​
No benefit as both just define a variable type, so the result is exactly the same, just an old school coding …​
 
Back
Top