欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門(mén)教程網(wǎng)!

C語(yǔ)言

當(dāng)前位置:主頁(yè) > 軟件編程 > C語(yǔ)言 >

C++Zip壓縮解壓縮示例(支持遞歸壓縮)

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C語(yǔ)言|點(diǎn)擊: 次



第三方函數(shù)、頭文件、測(cè)試工程下載地址:http://pan.baidu.com/s/1gSfKo

復(fù)制代碼 代碼如下:

// 文件名: ZipFunction.h
#pragma once
#include "zip.h"
#include "unzip.h"

namespace ZipUtils
{
    // ------------------------------------------------------------------------------------------------------------------------
    // Summary:
    //   解壓zip文件到指定路徑, 并返回解壓文件路徑和文件名。
    // Parameters:
    //   lpszZipFullName   - 待解壓 zip壓縮包所在文件夾路徑和zip壓縮名稱(chēng); 如"D://00//1.zip"。
    //   szFilePathArr     - 保存的解壓后文件的文件名;如"1.jpg"。   
    //   lpszUnZipPath     - 解壓出來(lái)的文件 所存放位置的完整路徑; 如 “D://01”
    //                       此參數(shù)省略時(shí),默認(rèn)解壓到exe程序所在文件夾下。
    // Returns:
    //   解壓成功返回ZR_OK,解壓失敗返回錯(cuò)誤碼。
    // ------------------------------------------------------------------------------------------------------------------------
    ZRESULT ExtractZipToDir(LPCTSTR lpszZipFullName, CStringArray& szFilePathArr, LPCTSTR lpszUnZipPath = NULL);

    // ------------------------------------------------------------------------------------------------------------------------
    // Summary:
    //   壓縮指定路徑下的文件,并保存壓縮包到指定路徑。
    // Parameters:
    //   lpszSrcPath        - 待壓縮文件所在的路徑; 如"D://00"。
    //   lpszDestPath       - 壓縮完成后,存放壓縮包的路徑。
    //                        此參數(shù)省略時(shí),默認(rèn)存放路徑為exe程序所在文件的路徑。
    //   lpszZipName        - 壓縮完成后,壓縮的名稱(chēng);如“MySkin.zip”。
    // Returns:
    //   壓縮成功返回ZR_OK,壓縮失敗返回錯(cuò)誤碼。
    // ------------------------------------------------------------------------------------------------------------------------
    ZRESULT CompressDirToZip(LPCTSTR lpszSrcPath, LPCTSTR lpszZipName, LPCTSTR lpszDestPath = NULL);
}

復(fù)制代碼 代碼如下:

#include "stdafx.h"
#include "ZipFunction.h"
#include <io.h>

namespace ZipUtils
{
    // 全局變量
    int g_nCount = 0;

    ZRESULT ExtractZipToDir(LPCTSTR lpszZipFullName, CStringArray& szFilePathArr, LPCTSTR lpszUnZipPath)
    {
        TCHAR buffer[MAX_PATH] = {0};
        CString strUnZipPath = lpszUnZipPath;
        DWORD zResult = ZR_OK;

        if (!strUnZipPath.IsEmpty())
        {
            // 如果文件路徑不存在先創(chuàng)建,存在不做任何修改
            SHCreateDirectoryEx(NULL, lpszUnZipPath, NULL);
        }
        else
        {
            GetCurrentDirectory(MAX_PATH, (LPTSTR)&buffer);
            strUnZipPath = buffer;
            SHCreateDirectoryEx(NULL, strUnZipPath, NULL);
        }

        HZIP hz = OpenZip(lpszZipFullName, 0);
        ZIPENTRY ze;

        GetZipItem(hz, -1, &ze);
        int numitems = ze.index;

        for (int zi = 0; zi < numitems; zi++)
        {
            ZIPENTRY ze;
            GetZipItem(hz,zi,&ze);
            zResult = UnzipItem(hz, zi, (CString)strUnZipPath+_T("\\")+ze.name);  
            szFilePathArr.Add(ze.name);
            if (zResult != ZR_OK)
            {
#ifndef _UNICODE
                // 判斷文件是否存在
                if (_access(szFilePathArr[zi], 0))   
                {
                    // 文件不存在的時(shí)候
                    return zResult;
                }
#else
                if (_access((char *)(LPTSTR)(LPCTSTR)szFilePathArr[zi], 0))   
                {
                    // 文件不存在的時(shí)候
                    return zResult;
                }
#endif
            }
        }

        CloseZip(hz);
        return zResult;
    }

    ZRESULT DirToZip(LPCTSTR lpszSrcPath, LPCTSTR lpszZipName, HZIP& hz, LPCTSTR lpszDestPath)
    {
        static CString strFileName;
        g_nCount++;
        DWORD zResult = ZR_OK;
        TCHAR buffer[MAX_PATH] = {0};

        CString strDestPath = lpszDestPath;

        if (g_nCount == 1)
        {
            // 這里邊的只執(zhí)行一次
            if (!strDestPath.IsEmpty())
            {
                // 如果解壓路徑文件夾不存在 先創(chuàng)建,存在 不做任何修改
                SHCreateDirectoryEx(NULL, lpszDestPath, NULL);
            }
            else
            {
                GetCurrentDirectory(MAX_PATH, (LPTSTR)&buffer);
                strDestPath = buffer;
                SHCreateDirectoryEx(NULL, strDestPath, NULL);
            }
            hz = CreateZip((CString)strDestPath+_T("\\")+(CString)lpszZipName, 0);
        }

        HANDLE file;
        WIN32_FIND_DATA fileData;
        file = FindFirstFile((CString)lpszSrcPath+_T("\\*.*"), &fileData);
        FindNextFile(file, &fileData);
        while (FindNextFile(file, &fileData))
        {
            // 如果是一個(gè)文件目錄
            if(fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                if (strFileName.IsEmpty())
                {
                    ZipAddFolder(hz, fileData.cFileName);
                }
                else
                {
                    ZipAddFolder(hz, strFileName+_T("\\")+fileData.cFileName);
                }

                strFileName = fileData.cFileName;
                // 存在子文件夾 遞歸調(diào)用
                DirToZip((CString)lpszSrcPath+_T("\\")+ fileData.cFileName, lpszZipName, hz, lpszDestPath);
                strFileName.Empty();
            }
            else
            {
                CString strTempPath;
                strTempPath.Format(_T("%s\\%s"), (CString)lpszSrcPath, fileData.cFileName);
                if (strFileName.IsEmpty())
                {
                    ZipAdd(hz, fileData.cFileName, strTempPath);
                }
                else
                {
                    ZipAdd(hz, strFileName+_T("\\")+fileData.cFileName, strTempPath);
                }

                if (zResult != ZR_OK)
                {
                    return zResult;
                }
            }
        }

        return zResult;
    }

    ZRESULT CompressDirToZip(LPCTSTR lpszSrcPath, LPCTSTR lpszZipName, LPCTSTR lpszDestPath)
    {
        HZIP hz;
        DWORD zResult = ZR_OK;
        zResult = DirToZip(lpszSrcPath, lpszZipName,hz, lpszDestPath);
        if(zResult == ZR_OK)
        {
            CloseZip(hz);
        }
        g_nCount = 0;

        return zResult;
    }
}

上一篇:c語(yǔ)言中使用BF-KMP算法實(shí)例

欄    目:C語(yǔ)言

下一篇:c++讀寫(xiě)文件流實(shí)例程序講解

本文標(biāo)題:C++Zip壓縮解壓縮示例(支持遞歸壓縮)

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/3887.html

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有