QZipReader支持zip文件中包含多个文件夹与文件的解压,直接上代码。
QString path = QString("D:/mulu");
{
QDir tempDir(path);
if(tempDir.exists()){
tempDir.removeRecursively();
}
tempDir.mkpath(path);
}
QString str = QString("D:/mulu") + QString("/1.zip");
QString path_main = QString("D:/mulu");
QZipReader reader(str);
for(auto fileInfo:reader.fileInfoList()){
if(fileInfo.isFile){
QFile file(path_main + "/"+fileInfo.filePath);
file.open(QIODevice::WriteOnly);
QByteArray name_data = fileInfo.filePath.toUtf8();
QString str_temp = QString::fromLocal8Bit(name_data);
QByteArray array = reader.fileData(str_temp);
file.write(array);
file.close();
}
else if(fileInfo.isDir){
QDir tempDir(path + "/"+fileInfo.filePath);
if(tempDir.exists()){
tempDir.removeRecursively();
}
tempDir.mkpath(path + "/"+fileInfo.filePath);
}
}
reader.close();