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

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

// 下面是使用该类:

// 使用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来分辨是文件 还是 文件夹。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值