Extract files from a zip file

Here is my scenario:
I have a zip file, DataStore.zip, which as two layers of zip files.
                                     DataStore.zip
                                           |
           01.zip       02.zip         03.zip      04.zip etc
                             |
                 02a.zip          02b.zip         02c.zip        
 etc
                     |
            cert1.zip   cert2.zip     cert3.zip     etc
I need to search for  any cert.zip embedded at layer3, for which I have written the following program.
I have two issues. First one is, when the files at level 1 (01.zip etc are written to the disk folder c:\ extract, it doesn't allow me to read back from that folder., I get "access to path c:\extract is denied". I researched and found that this
is a security issue with windows 8 and 7. ( I tried both versions). How can I overcome this?
second issue is, if in the  first read cycle  it fails with "unknown block type, stream may be corrupted", I need to bypass that corrupted zip file and continue, until I get my target file.
The code is give below. Appreciate any help.. Thanks.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.IO.Compression;
namespace TPMCert
{   // Utility to copy a TPM certificate from the master file.
    public partial class Form1 : Form
        public Form1()
            InitializeComponent();
        private void Form1_Load(object sender, EventArgs e)
        private void btnSelDrv_Click(object sender, EventArgs e)
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                string filePath1 = this.folderBrowserDialog1.SelectedPath; //
                this.txtDrv.Text = filePath1;
        }//btnselDrv
        private void btnTpmReq_Click(object sender, EventArgs e)
                OpenFileDialog openFile1 = new OpenFileDialog();
                if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    txtRqstFileName.Text = openFile1.FileName.Remove(0, 3); //remove first 3 chars which is c:/ etc
        private void btnGo_Click_1(object sender, EventArgs e)
                string zPath = txtDrv.Text + "\\" +"TpmDataStore.zip"; //drive & filename to to search.....
                string extractPath= txtDrv.Text
+@"\extract";
                string extractPath2 = txtDrv.Text + @"\extract\certs";
                string copyPath = txtDrv.Text; // location of the tpm certificate finall written to..
                bool filefound = false;
                 //look for the file. read only allowed...
               // try
                    using (ZipArchive archive = ZipFile.OpenRead(zPath)) //open Tpm file for reading
                        txtInfo.AppendText("Processing ....  Please wait!" + "\n");
                        Cursor.Current = Cursors.WaitCursor; //busy cursor
                        foreach (ZipArchiveEntry zEntry in archive.Entries) //each top level zip file is written to \extract dir
                            zEntry.ExtractToFile(Path.Combine(extractPath, zEntry.FullName), true); //true- overwrite
                            txtInfo.AppendText(" First write passed...");
                            //next iterate thro' all zip files in \extract dir
                           using (ZipArchive archive2 =ZipFile.Open(extractPath, ZipArchiveMode.Update)) //read files in extract
                               foreach (ZipArchiveEntry childEntry in archive2.Entries)
                                   childEntry.ExtractToFile(Path.Combine(extractPath2,
childEntry.Name), true); //true- overwrite
                                   MessageBox.Show(childEntry.Name);
                                   txtInfo.AppendText(" Second cycle....");
                                   if (childEntry.Name == txtRqstFileName.Text)
                                           filefound
= true; //
                                           //MessageBox.Show(zEntry.FullName);
                                           txtInfo.AppendText("Found
file " + childEntry.Name + "\n");
                                           txtInfo.AppendText("File
copied as " + copyPath + "\\" + childEntry.Name + "\n");
                            }//second using..
                        }//foreach
                        if (filefound == false ) // given file is not there
                            txtInfo.AppendText("File not found" +  "\n");
                    }//using
                }//try
                   // catch (Exception ex)
                           // MessageBox.Show(" Error:" + "\n" + ex.Message);
                            return;
                         //finally
                        { Cursor.Current = Cursors.Default;
            // next
        } //btnGo..
    }//class form1
}//namespace

Hi friend,
We'd better to ask one question in each thread. If you have another issue, you can consider to open up a new thread in this forum.
Now for the first question, do you mean this picture? It throws access exception in archive2.
If so , because your extractPath is a path, not a directory.You should add +"xxx.zip". For more information, please refer to
ZipFile.Open
Method (String, ZipArchiveMode).
For the second question, you can use the following code to skip the error message.
while (true)
try
//do something;
catch (Exception ex)
{ continue; }
Good day!
Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.

Similar Messages

  • Reading a Compressed File from a ZIP File, which is an entry of ZIP File

    Hello, Experts,
    Would it be possible somebody to help me with code example for the following problem?
    I want to read a compressed file from a ZIP file, which is an entry of ZIP File, without extacting/writing files on file system. Is this possible?
    Lets say we have a ZipFile1. There is ZipFile2 inside ZipFile1. And inside ZipFile2 is FileA. The scenario is reading FileA without extracting on file system.
    Thank you in advance for your help.
    Cheers
    RADY

    The classes you want to be using are java.util.zip.ZipInputStream and and ZipEntry from the same package. Construct the ZipInputStream with the input you have for the outer zip. Loop with ZipInputStream.getNextEntry until you find the inner zip you're looking for - that method returns a ZipEntry, and you get the name of the zip entry with ZipEntry.getName. Read the ZipInputStream from that point into some buffer, and read that buffer into a new ZipInputStream - rinse and repeat until you have the contents of the file in the zip in the zip...

  • How to exreact multiple pdf files from a zip files from application server to presentation server

    Hello exprts,
    I am passing one pdf file and one text file to zip file in apllication server through my custom program and then downloading it using standard function module to my desktop. its working fine. Then I added  another pdf file to my zip file. But only single pdf file is getting download . So can you please help me regardiong this issue? 

    Dear Experts ,
    I finded out the way to extrcat pdf files in presentation server. But now my problem is that I am not able to add multiple pdf files in a zip file. When I am adding new pdf file then older one is not coming in read data set. So please kindly tell me how can I add multiple pdf file in my zip file and again I can get all the pdf files from here.

  • Extracting file from a TAR file with java.util.zip.* classes

    Is there a way to extract files from a .TAR file using the java.util.zip.* classes?
    I tried in some ways but I get the following error:
    java.util.zip.ZipException: error in opening zip file
    at java.util.zip.ZipFile.<init>(ZipFile.java127)
    at java.util.zip.ZipFile.<init>(ZipFile.java92)
    Thank you
    Giuseppe

    download the tar.jar from the above link and use the sample program below
    import com.ice.tar.*;
    import java.util.zip.GZIPInputStream;
    import java.io.*;
    public class untarFiles
         public static void main(String args[]){
              try{
              untar("c:/split/20040826172459.tar.gz",new File("c:/split/"));
              }catch(Exception e){
                   e.printStackTrace();
                   System.out.println(e.getMessage());
         private static void untar(String tarFileName, File dest)throws IOException{
              //assuming the file you pass in is not a dir
              dest.mkdir();     
              //create tar input stream from a .tar.gz file
              TarInputStream tin = new TarInputStream( new GZIPInputStream( new FileInputStream(new File(tarFileName))));
              //get the first entry in the archive
              TarEntry tarEntry = tin.getNextEntry();
              while (tarEntry != null){//create a file with the same name as the tarEntry  
                   File destPath = new File(
                   dest.toString() + File.separatorChar + tarEntry.getName());
                   if(tarEntry.isDirectory()){   
                        destPath.mkdir();
                   }else {          
                        FileOutputStream fout = new FileOutputStream(destPath);
                        tin.copyEntryContents(fout);
                        fout.close();
                   tarEntry = tin.getNextEntry();
              tin.close();
    }

  • Receive Pipeline In Decoder Stage to Extract Single Or Multiple Files From A Zipped Folder In Biztalk Server 2010

    Hi,
    I need help in developing a customized pipeline for the Decoder Stage.
    Requirement : Extract single or multiple files from a zipped folder with any format and extension (X12/EDIFACT/Flat/XML) and send to Disassemble stage for further action.
    Need Urgent help.
    Any suggestion or help is much appreciated.
    Thanks & Best Regards

    Hi Siddharth,
    Have look at article: BizTalk Server 2010: Processing Zip Message Having Multiple Type
    Files and http://tech-findings.blogspot.com/2013/10/custom-zipreceivepipeline-to-unzip.html
    Maheshkumar S Tiwari|User
    Page|Blog|BizTalk
    Server : Scheduling Orchestration using Trigger Message

  • How to extract text from a PDF file?

    Hello Suners,
    i need to know how to extract text from a pdf file?
    does anyone know what is the character encoding in pdf file, when i use an input stream to read the file it gives encrypted characters not the original text in the file.
    is there any procedures i should do while reading a pdf file,
    File f=new File("D:/File.pdf");
                   FileReader fr=new FileReader(f);
                   BufferedReader br=new BufferedReader(fr);
                   String s=br.readLine();any help will be deeply appreciated.

    jverd wrote:
    First, you set i once, and then loop without ever changing it. So your loop body will execute either 0 times or infinitely many times, writing the same byte every time. Actually, maybe it'll execute once and then throw an ArrayIndexOutOfBoundsException. That's basic java looping, and you're going to need a firm grip on that before you try to do anything as advanced as PDF reading. the case.oops you are absolutely right that was a silly mistake to forget that,
    Second, what do the docs for getPageContent say? Do they say that it simply gives you the text on the page as if the thing were a simple text doc? I'd be surprised if that's the case.getPageContent return array of bytes so the question will be:
    how to get text from this array? i was thinking of :
        private void jButton1_actionPerformed(ActionEvent e) {
            PdfReader read;
            StringBuffer buff=new StringBuffer();
            try {
                read = new PdfReader("d:/getjobid2727.pdf");
                read.getMetaData();
                byte[] data=read.getPageContent(1);
                int i=0;
                while(i>-1){ 
                    buff.append(data);
    i++;
    String str=buff.toString();
    FileOutputStream fos = new FileOutputStream("D:/test.txt");
    Writer out = new OutputStreamWriter(fos, "UTF8");
    out.write(str);
    out.close();
    read.close();
    } catch (Exception f) {
    f.printStackTrace();
    "D:/test.txt"  hasn't been created!! when i ran the program,
    is my steps right?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to extract text from a PDF file using php?

    How to extract text from a PDF file using php?
    thanks
    fabio

    > Do you know of any other way this can be done?
    There are many ways. But this out of scope of this forum. You can try this forum: http://forum.planetpdf.com/

  • How to Extract data from a flat file and how to upload it into table

    Hi
    i want to extract the data from a web page, that data i want to keep in text file.
    from the text file i want to read it and i want to upload into table
    can any one help me its very urgent

    here is my 20min try without debugging (needs a rs232 and loopback connector )
    use the probe and highlight the dataflow to see how it works.
    as always:  there are many ways to solve your problem
    Greetings from Germany
    Henrik
    LV since v3.1
    “ground” is a convenient fantasy
    '˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'
    Attachments:
    read write file to RS232.vi ‏69 KB

  • How to Extract Data from the PDF file to an internal table.

    HI friends,
    How can i Extract data from a PDF file to an internal table....
    Thanks in Advance
    Shankar

    Shankar,
    Have a look at these threads:-
    extracting the data from pdf  file to internal table in abap
    Adobe Form (data extraction error)
    Chintan

  • How to create a Web Dynpro Project from Downloaded zip file?

    Hi,
    I have been working in Java Web Dynpro for last 1 month but not able
    to create any Web Dynpro from Downloaded zip file?
    Can anybody tell me how to create a Java Web Dynpro Project from
    Donloaded zip code?
    Regards
    Kaushik Banerjee

    Hi Kaushik,
    You can add the existing zip file into your workspace by the following way -
    First open the NWDS and create a new project by clicking file -> new -> Project -> Simple -> Project
    and then File -> Import -> zipfile and then browse the zip file into the newly created project.
    or else you can also unzip the zip file into a folder and then Use the option of Import an exisitng project into workspace. You can find this in the File-> import -> Existing project into workspace. and then use the Browse option to browse to the existing folder.
    After importing the project you need to rebuild the project
    Regards,
    Raju Bonagiri.

  • How can I extract data from a sound file in carbon

    hello,
    I am a student and I start recently learning carbon. I have to do a application which can read and extract data from a sound file and use that data to do some kind of visual representation of the file. I would like to know if someone can give some directions, tutorial,some code sample etc.
    thank you for your help
    chenita7

    hello orangekay
    My idea is to create an application that can read a sound file( AIFF, MP3 or other) in order to extract some kind of data ( numbers or any values) and use that data to represent the sound file visually.
    I dont know which kind of data can be extract from a sound file, and in which way i can manipulate that data to became a visual representation of the sound file. this is what I want to do as my second assignment for a subject at school, introduction to programming. has to be done based in carbon.
    regards
    chenita7

  • Hello, I am attempting to install Camera raw from a .zip file provided via a link provided by adobe for a Nikon D810. The .zip file unzips fine and I moved the files to the recommended folder. But the operation is failing

    I am attempting to install Camera raw from a .zip file provided via a link provided by adobe for a Nikon D810. The .zip file unzips fine and I moved the files to the recommended folder. But the operation is failing

    Can you describe what “the operation is failing” means?  What is happening and how is it different than what you expect?
    Also, what product are you trying to update manually, and do you have a link to the page of instructions, so we know what your attempting to do?

  • Hi i am new to labview. i want to extract data from a text file and display it on the front panel. how do i proceed??

    Hi i am new to labview
    I want to extract data from a text file and display it on the front panel.
    How do i proceed??
    I have attached a file for your brief idea...
    Attachments:
    extract.jpg ‏3797 KB

    RoopeshV wrote:
    Hi,
    The below code shows how to read from txt file and display in the perticular fields.
    Why have you used waveform?
    Regards,
    Roopesh
    There are so many things wrong with this VI, I'm not even sure where to start.
    Hard-coding paths that point to your user folder on the block diagram. What if somebody else tries to run it? They'll get an error. What if somebody tries to run this on Windows 7? They'll get an error. What if somebody tries to run this on a Mac or Linux? They'll get an error.
    Not using Read From Spreadsheet File.
    Use of local variables to populate an array.
    Cannot insert values into an empty array.
    What if there's a line missing from the text file? Now your data will not line up. Your case structure does handle this.
    Also, how does this answer the poster's question?

  • Permissions issues with files from a zip

    We've got five macs on a network, all on 10.5.6. Clients often send us folders with files in as a single zip. If the zip file is opened, the folder and files all have read/Write permission for the user that opened the zip, and all other macs have "no access". This happens with all the macs. The zip files are sent from PCs.
    Has anyone any idea as to why this should happen, and a possible fix?
    Cheers
    Steve

    im now trying this method instead, it kind of works, but reads in all files (I just wanted XML files), and Im sure its not the best method for this:
    public void readZipXMLFiles(String inFilename)
    try {
            // Open the ZIP file
            ZipInputStream in = new ZipInputStream(new FileInputStream(inFilename));
            // Get the first entry
            ZipEntry entry;
            entry = in.getNextEntry();
            while (entry != null){
            // Open the output file
            String entryName = entry.getName();
            String outFilename = entryName;
            OutputStream out = new FileOutputStream(outFilename);
            CheckExtension("xml", entry.getName());
            // this check the file extension, if correct FileType=true
            System.out.println(entry.getName()+ ":" + FileType);
            if (FileType == true){
            // Transfer bytes from the ZIP file to the output file
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            // Close the streams
            entry = in.getNextEntry();
            out.close();
            in.close();
        } catch (IOException e) {
            catch (Exception e)
                e.printStackTrace();
        }Because I'm using a ZipInputStream, its grabbing all files even if the files are not .xml,
    Edited by: Mr_Tuition on Dec 18, 2007 7:05 AM
    Edited by: Mr_Tuition on Dec 18, 2007 7:08 AM

  • Extracting a Password Protected zip file

    Can anybody help me to extract a password protected zip file? Using java code or any third party API...??

    Can anybody help me to extract a password protected zip file?You'll need the password ;)
    Using java code nope
    any third party API...?? Yup.

Maybe you are looking for

  • My Macbook Air connects to ATV at home but not at work

    My Macbook Air connects at home over a Time Machine network to my apple tv just fine (including airplay); when at work on a non-apple wifi network both computer and apple tv connect but cannot see each other.  As I would like to stream video to the w

  • MM: PO Not Picking up PR Having Multiple Line Items

    Hi All, When Creating PO with Reference to PR Having multiple line items, not picking up the line items and also the vendor and also the where in we  have to select  input tax code. CASE1: Created PR 760001340 with single line item and also could abl

  • Recovery from computer generated "Recovery Disks".

    I have a notebook G62-340us with Win7. At bootup on the splash screen I have been getting a message that states the hard drive is going to fail etc. I replaced the drive with two new drives ( seperate occasions)  but the computer generated recovery d

  • Itunes for mac will not launch

    my itunes will not launch have updated to 11. tried reboot.  when trying to start the Icon bounces in the task bar then stops when you click on it says that it stopped responding seems to be only app having this prroblem.  Thanks for your help.

  • LimeWire doesn't connect on Mac OS X Leopard... What's the problem???

    I've got constantly firewall icon on and one bar in the connection progress...... When I put my tracking arrow on it, it shows: "You are currently connecting to the network"..... I tried to restart Mac, but it doesn't help.... What I'm supposed to do