只能压缩解压zip格式的,不需要dll或者库文件,核心是HZIP,支持带密码压缩解压(但是有时不完美,属于HZIP本身的问题,请不要纠结这一点)。
以下为核心封装文件,建议大家下载源代码查看,下载地址在本文末尾。
/////////////////////////////////////////////////////////////////////////////
// 文件名: <ZipImplement.h>
// 说明:压缩解压缩文件夹
/////////////////////////////////////////////////////////////////////////////
#pragma once
//#include "stdafx.h"
#include <atlconv.h>
#include "Zip.h"
#include "Unzip.h"
class CZipImplement
{
public:
CZipImplement(void);
~CZipImplement(void);
private:
HZIP hz;//Zip文件句柄
ZRESULT zr;//操作返回值
ZIPENTRY ze;//Zip文件入口
CString m_FolderPath;//folder路径
CString m_FolderName;//folder将要被压缩的文件夹名
private:
//实现遍历文件夹
void BrowseFile(CString &strFile);
//获取相对路径
void GetRelativePath(CString& pFullPath, CString& pSubString);
//创建路径
BOOL CreatedMultipleDirectory(wchar_t* direct);
public:
//压缩文件夹接口
BOOL Zip_PackFiles(CString& pFilePath, CString& mZipFileFullPath, CStringA strPW = "");
//解压缩文件夹接口
BOOL Zip_UnPackFiles(CString &mZipFileFullPath, CString& mUnPackPath, CStringA strPW = "");
public:
//静态方法提供文件夹路径检查
static BOOL FolderExist(CString& strPath);
};
/////////////////////////////////////////////////////////////////////////////
// 文件名: <ZipImplement.cpp>
// 说明:压缩解压缩文件夹
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "zipimplement.h"
#include <direct.h>
#include <vector>
#include <xstring>
CZipImplement::CZipImplement(void)
{
}
CZipImplement::~CZipImplement(void)
{
}
/////////////////////////////////////////////////////////////////////////////
// 函数说明: 实现压缩文件夹操作
// 参数说明: [in]:
// pFilePath 要被压缩的文件夹
// mZipFileFullPath 压缩后的文件名和路径
// strPW 压缩密码,可空,默认为空,表示不带密码压缩
// 返回值: 参数有误的情况下返回FALSE,压缩成功后返回TRUE
/////////////////////////////////////////////////////////////////////////////
BOOL CZipImplement::Zip_PackFiles(CString& pFilePath, CString& mZipFileFullPath, CStringA strPW)
{
//参数错误
if ((pFilePath == L"") || (mZipFileFullPath == L""))
{
//路径异常返回