Results 1 to 2 of 2

Thread: unzip zip file contains files and folders with quazip

  1. #1
    Join Date
    Jul 2013
    Posts
    9
    Thanks
    5

    Default unzip zip file contains files and folders with quazip

    I want to extract a zip file contains files and folders using quazip in Qt but I have not find a good solution yet. I have searched and just found the way to extract zip file with files only, not contains folders. Does anyone can help me? Thanks a lot!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: unzip zip file contains files and folders with quazip

    Ignore the spam above.

    QuaZip gives you the full path along with the file name as you step through the archive. It is just a matter of recognising that and creating directories as you go.
    This test file:
    Qt Code:
    1. $ unzip -l test.zip
    2. Archive: test.zip
    3. Length Date Time Name
    4. --------- ---------- ----- ----
    5. 0 11-07-2013 17:06 a/
    6. 0 11-07-2013 17:05 a/test1.txt
    7. 0 11-07-2013 17:05 a/test2.txt
    8. 0 11-07-2013 17:06 a/b/
    9. 0 11-07-2013 17:06 a/b/test3.txt
    10. --------- -------
    11. 0 5 files
    To copy to clipboard, switch view to plain text mode 
    this code:
    Qt Code:
    1. #include <QtCore>
    2. #include <quazip/quazip.h>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QCoreApplication app(argc, argv);
    7.  
    8. QuaZip zip("test.zip");
    9. if (zip.open(QuaZip::mdUnzip)) {
    10. qDebug() << "Opened";
    11.  
    12. for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) {
    13. // do something
    14. qDebug() << zip.getCurrentFileName();
    15. }
    16. if (zip.getZipError() == UNZ_OK) {
    17. // ok, there was no error
    18. }
    19. }
    20. return 0;
    21. }
    To copy to clipboard, switch view to plain text mode 
    this result:
    Qt Code:
    1. Opened
    2. "a/"
    3. "a/test1.txt"
    4. "a/test2.txt"
    5. "a/b/"
    6. "a/b/test3.txt"
    To copy to clipboard, switch view to plain text mode 
    So, if the file name ends with '/' create a directory, otherwise create a file and extract the data into it.

Similar Threads

  1. Using quazip for extracting multiple files.
    By akshaysulakhe in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2013, 10:59
  2. Need simple example with OSDaB-Zip unzip file
    By noborder in forum Newbie
    Replies: 2
    Last Post: 17th January 2013, 22:59
  3. Replies: 1
    Last Post: 27th September 2011, 07:32
  4. viewing files or some folders
    By as001622 in forum Qt Programming
    Replies: 4
    Last Post: 2nd June 2008, 13:12
  5. OpenOffice file to QTextEdit (Unzip Problem)
    By patrik08 in forum Qt Programming
    Replies: 6
    Last Post: 27th November 2006, 11:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.