设为首页 加入收藏

TOP

使用VC++压缩解压缩文件夹(一)
2014-11-23 19:19:21 】 浏览:710
Tags:使用 压缩 文件夹
前言
项目中要用到一个压缩解压缩的模块, 看了很多文章和源代码,
都不是很称心, 现在把我自己实现的代码和大家分享.
要求:
1.使用Unicode(支持中文).
2.使用源代码.(不使用静态或者动态库)
3.实现文件夹压缩解压缩即可.(不提供单文件压缩和内存压缩)
4.压缩格式为ZIP.
5.具有一定的容错能力.(判断用户输入的内容)
代码如下:
*********************ZipImplement.h********************
1/////////////////////////////////////////////////////////////////////////////
2// 文件名:
3// 创建者:
4// 创建日期: 2009-09-27 下午 04:51:46
5//
6// 说明:压缩解压缩地图文件夹
7/////////////////////////////////////////////////////////////////////////////
8
9#pragma once
10
11#include "zip.h"
12#include "unzip.h"
13
14class CZipImplement
15{
16public:
17 CZipImplement(void);
18 ~CZipImplement(void);
19
20private:
21 HZIP hz; //Zip文件句柄
22 ZRESULT zr; //操作返回值
23 ZIPENTRY ze; //Zip文件入口
24
25 CString m_FolderPath; //folder路径
26 CString m_FolderName; //folder将要被压缩的文件夹名
27
28private:
29 //实现遍历文件夹
30 void BrowseFile(CString &strFile);
31
32 //获取相对路径
33 void GetRelativePath(CString& pFullPath, CString& pSubString);
34
35 //创建路径
36 BOOL CreatedMultipleDirectory(wchar_t* direct);
37 ///*
38 //***********************************************************************
39 //* 函数: TransCStringToTCHAR
40 //* 描述:将CString 转换为 TCHAR*
41 //***********************************************************************
42 //*/
43 //TCHAR* CString2TCHAR(CString &str)
44 //{
45 // int iLen = str.GetLength();
46 // TCHAR* szRs = new TCHAR[iLen];
47 // lstrcpy(szRs, str.GetBuffer(iLen));
48 // str.ReleaseBuffer();
49 // return szRs;
50 //}
51
52public:
53 //压缩文件夹接口
54 BOOL Zip_PackFiles(CString& pFilePath, CString& mZipFileFullPath);
55
56 //解压缩文件夹接口
57 BOOL Zip_UnPackFiles(CString &mZipFileFullPath, CString& mUnPackPath);
58
59public:
60 //静态方法提供文件夹路径检查
61 static BOOL FolderExist(CString& strPath);
62};
*********************ZipImplement.cpp*********************
1/////////////////////////////////////////////////////////////////////////////
2// 文件名:
3// 创建者:
4// 创建日期: 2009-09-27 下午 04:51:46
5//
6// 说明:压缩解压缩地图文件夹
7/////////////////////////////////////////////////////////////////////////////
8
9#include "StdAfx.h"
10#include "zipimplement.h"
11#include
12#include
13#include
14
15CZipImplement::CZipImplement(void)
16{
17}
18
19CZipImplement::~CZipImplement(void)
20{
21}
22
23/////////////////////////////////////////////////////////////////////////////
24// 函数说明: 实现压缩文件夹操作
25// 参数说明: [in]: pFilePath 要被压缩的文件夹
26// mZipFileFullPath 压缩后的文件名和路径
27// 返回值: 参数有误的情况下返回FALSE,压缩成功后返回TRUE
28// 函数作者:
29// 创建日期: 2009-09-27 下午 04:58:52
30/////////////////////////////////////////////////////////////////////////////
31BOOL CZipImplement::Zip_PackFiles(CString& pFilePath, CString& mZipFileFullPath)
32{
33 //参数错
首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇VC中Tab control的用法 下一篇VC实现将对话框最小化到系统托盘

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目