Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9011835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:50:43+00:00 2026-06-16T02:50:43+00:00

I have a directory with files and folders that I would like to zip.

  • 0

I have a directory with files and folders that I would like to zip. I’m using the qt-project quazip for it. So I thought I write a function that packs all content of a directory including the filestructure.

How can I create the folder in the zip-file? I tried it with QuaZipNewInfo but couldn’t make it work.

For example I want to zip the tmp-folder with this content:

tmp/1.txt
tmp/folder1/2.txt
tmp/folder1/3.txt
tmp/folder2/4.txt
tmp/folder2/folder3/5.txt

What I get after extracting the file with a common archive-tool (Archive Utility) is this:

tmp/1.txt
tmp/2.txt
tmp/3.txt
tmp/4.txt
tmp/5.txt

This is what I have so far:

void Exporter::zipFilelist(QFileInfoList& files, QuaZipFile& outFile, QFile& inFile, QFile& inFileTmp)
{
    char c;
    foreach(QFileInfo file, files) {
        if(file.isDir()  && file.fileName() != "." && file.fileName() != "..") {
            QFileInfoList infoList = QDir(file.filePath()).entryInfoList();
            zipFilelist(infoList, outFile, inFile, inFileTmp);
        }
        if(file.isFile()) {
            inFileTmp.setFileName(file.fileName());
            inFile.setFileName(file.filePath());

            if(!inFile.open(QIODevice::ReadOnly)) {
                qDebug() << "testCreate(): inFile.open(): " << inFile.errorString().toLocal8Bit().constData();
            }
            QuaZipNewInfo info(inFileTmp.fileName(), inFile.fileName());
            if(!outFile.open(QIODevice::WriteOnly, info)) {
                qDebug() << "testCreate(): outFile.open(): " << outFile.getZipError();
            }
            while(inFile.getChar(&c)&&outFile.putChar(c)) ;
            if(outFile.getZipError()!=UNZ_OK) {
                qDebug() << "testCreate(): outFile.putChar(): %d"<< outFile.getZipError();
            }

            outFile.close();
            if(outFile.getZipError()!=UNZ_OK) {
                qDebug() << "testCreate(): outFile.close(): %d"<< outFile.getZipError();
            }
            inFile.close();
        }
    }
}

And this is how I call the function:

QFileInfoList files = QDir(sourceFolder).entryInfoList();
QFile inFile;
QFile inFileTmp;
QuaZipFile outFile(&zip);
zipFilelist(files, outFile, inFile, inFileTmp);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:50:45+00:00Added an answer on June 16, 2026 at 2:50 am

    I don’t get any error. When I want to unzip the file it doesn’t extract the folders (because I probably don’t pack them into the zip!?). So I get all files of all subfolders unziped into one folder.

    It seems that in your function you were recursively getting the files in the folders, but not the folders themselves. Try creating a folder to zip the files into when you recurse into looking for the files in the subdirectory.

    You may want to look into this answer:
    https://stackoverflow.com/a/2598649/1819900

    How about the utilities provided by QuaZip?
    http://quazip.sourceforge.net/classJlCompress.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a directory with files that look like this: 001_something.php 002_something_else.php 004_xyz.php 005_do_good_to_others.php
I have path like this...C:\restore\restoredb\ In that path i have files like this.. backup-2011-10-12T17-16-51.zip
If I have a development area that I deleted files from a certain folder/directory,
I have a directory of ZIP files (created on a Windows machine). I can
I have a folder structure that I would like to have in my bundle.
I would like a rule something like: build/%.ext: src/%.ext action I have one directory
I have a project where the directory structure is like this: $projectroot | +---------------+----------------+
I would like to read a lot of files from different folders. Now I
If I have a directory structure like so on a web service that sends
I have a data model for a directory type structure that looks something like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.