压缩解压缩文件和文件夹(三)

来源:互联网 发布:淘宝运营团队如何收费 编辑:程序博客网 时间:2024/06/05 17:47

// 续 压缩解压缩文件和文件夹(二)

// 下面是使用该类:

// 使用VC6.0,创建单对话框工程,命名为Testzip
// 在对话框的实现文件中加上面的类的头文件引入:#include "include/zipimplement.h"
// 在对话框上添加2个按钮:IDC_BTNZIP,IDC_BTNUNZIP,分别为压缩和解压的按钮,然后添加but事件。在其实现中添加如:
// m_strDirPath为成员变量,我是为了在其他程序地方使用而定义的,这个也可以定位临时变量。

void CTestzipDlg::OnBtnzip() 
{
// TODO: Add your control notification handler code here
CString m_strDirPath= "";
GetModuleFileName(NULL, m_strDirPath.GetBufferSetLength(MAX_PATH+1), MAX_PATH);
m_strDirPath.ReleaseBuffer();
int nPos = m_strDirPath.ReverseFind('\\');
m_strDirPath = m_strDirPath.Left(nPos);
// 工作路径下测试--压缩: 删除bin目录下src.zip、zip.zip
CZipImplement czip;
CString pFilePath = m_strDirPath+"\\src";
CString mZipFileFullPath = m_strDirPath+"\\src.zip";
pFilePath.Replace("\\", "/");
mZipFileFullPath.Replace("\\", "/");
czip.ZipPackFiles(pFilePath, mZipFileFullPath, true); // 文件夹
pFilePath = m_strDirPath+"\\zip.h";
mZipFileFullPath = m_strDirPath+"\\zip.zip";
pFilePath.Replace("\\", "/");
mZipFileFullPath.Replace("\\", "/");
czip.ZipPackFiles(pFilePath, mZipFileFullPath, false); // 文件  
MessageBox("OK");
}


void CTestzipDlg::OnBtnunzip() 
{
// TODO: Add your control notification handler code here
CString m_strDirPath= "";
GetModuleFileName(NULL, m_strDirPath.GetBufferSetLength(MAX_PATH+1), MAX_PATH);
m_strDirPath.ReleaseBuffer();
int nPos = m_strDirPath.ReverseFind('\\');
m_strDirPath = m_strDirPath.Left(nPos);
// 工作路径下测试-解压: 删除bin目录下src、zip.h
CZipImplement czip;
CString pFilePath = m_strDirPath+"\\";
CString mZipFileFullPath = m_strDirPath+"\\src.zip";
pFilePath.Replace("\\", "/");
mZipFileFullPath.Replace("\\", "/");
czip.ZipUnPackFiles(mZipFileFullPath, pFilePath, true); // 文件夹
pFilePath = m_strDirPath;
mZipFileFullPath = m_strDirPath+"\\zip.zip";
pFilePath.Replace("\\", "/");
mZipFileFullPath.Replace("\\", "/");
czip.ZipUnPackFiles(mZipFileFullPath, pFilePath, false); // 文件
MessageBox("OK");
}
// 这样就可以了,程序内容大家都知道。我是为了方便,在类中使用了bool来分辨是文件 还是 文件夹。
// 工程和demo下载地址:http://download.csdn.net/detail/welove20101/7341291

0 0