最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實現(xiàn)Zip壓縮目錄中所有文件的方法

 更新時間:2015年07月15日 16:13:00   作者:DTC2  
這篇文章主要介紹了C#實現(xiàn)Zip壓縮目錄中所有文件的方法,涉及C#針對文件的讀寫與zip壓縮相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了C#實現(xiàn)Zip壓縮目錄中所有文件的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

using System;
using System.IO;
using System.Collections;
using System.IO.Compression;
using System.Collections.Generic;
class FolderZip
{
private const long BUFFER_SIZE = 20480;
static void main(string[] args)
{
string sourcepath=@"C:\tmp";
Queue<FileSystemInfo> Folders = new Queue<FileSystemInfo>(new DirectoryInfo(sourcepath).GetFileSystemInfos());
string copytopath = @"D:\temp";
copytopath = (copytopath.LastIndexOf(Path.DirectorySeparatorChar) == copytopath.Length - 1) ? copytopath : copytopath+Path.DirectorySeparatorChar + Path.GetFileName(sourcepath);
Directory.CreateDirectory(copytopath);
while (Folders.Count > 0)
{
 FileSystemInfo atom = Folders.Dequeue();
 FileInfo sourcefile = atom as FileInfo;
 if (sourcefile == null)
 {
  DirectoryInfo directory = atom as DirectoryInfo;
  Directory.CreateDirectory(directory.FullName.Replace(sourcepath,copytopath));
  foreach (FileSystemInfo nextatom in directory.GetFileSystemInfos())
  Folders.Enqueue(nextatom);
 }
 else
 {
  string sourcefilename = sourcefile.FullName;
  string zipfilename = sourcefile.FullName.Replace(sourcepath,copytopath) + ".zip";
  if (!File.Exists(zipfilename))
  {
   FileStream sourceStream = null;
   FileStream destinationStream = null;
   GZipStream compressedStream = null;
   try
   {
    // Read the bytes from the source file into a byte array
    sourceStream = new FileStream(sourcefilename, FileMode.Open, FileAccess.Read, FileShare.Read);
    // Open the FileStream to write to
    destinationStream = new FileStream(zipfilename, FileMode.OpenOrCreate, FileAccess.Write);
    // Create a compression stream pointing to the destiantion stream
    compressedStream = new DeflateStream(destinationStream, CompressionMode.Compress, true);
    long bufferSize = sourceStream.Length < BUFFER_SIZE ? sourceStream.Length : BUFFER_SIZE;
    byte[] buffer = new byte[bufferSize];
    int bytesRead = 0;
    long bytesWritten = 0;
    while ((bytesRead = sourceStream.Read(buffer, 0, buffer.Length)) != 0)
    {
     compressedStream.Write(buffer, 0, bytesRead);
     bytesWritten += bufferSize;
    }
   }
   catch (ApplicationException)
   {
    continue;
   }
   finally
   {
    // Make sure we allways close all streams
    if (sourceStream != null) sourceStream.Close();
    if (compressedStream != null) compressedStream.Close();
    if (destinationStream != null) destinationStream.Close();
   }
  }
 }
}
}
}

希望本文所述對大家的C#程序設(shè)計有所幫助。

相關(guān)文章

  • C#接口歸納總結(jié)實例詳解

    C#接口歸納總結(jié)實例詳解

    本篇文章通過實例代碼對接口做了詳解,需要的朋友可以參考下
    2017-04-04
  • C#和Java有什么區(qū)別和聯(lián)系

    C#和Java有什么區(qū)別和聯(lián)系

    這篇文章主要介紹了C#和Java有什么區(qū)別和聯(lián)系的相關(guān)資料,本文介紹的非常詳細,涉及到rsa語法,c#和java互轉(zhuǎn)方面的知識點,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-07-07
  • C#關(guān)鍵字之覆寫overwrite介紹

    C#關(guān)鍵字之覆寫overwrite介紹

    這篇文章介紹了C#關(guān)鍵字之覆寫overwrite,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • C#集成DeepSeek模型實現(xiàn)AI私有化的流程步驟(本地部署與API調(diào)用教程)

    C#集成DeepSeek模型實現(xiàn)AI私有化的流程步驟(本地部署與API調(diào)用教程)

    本文主要介紹了C#集成DeepSeek模型實現(xiàn)AI私有化的方法,包括搭建基礎(chǔ)環(huán)境,如安裝Ollama和下載DeepSeek?R1模型,客戶端?ChatBox?AI?接入?DeepSeek?的步驟,以及?C#?調(diào)用?DeepSeek?API?的示例代碼,并總結(jié)了其在實際項目中的應(yīng)用價值,需要的朋友可以參考下
    2025-03-03
  • C# Base64編碼函數(shù)

    C# Base64編碼函數(shù)

    Base64編碼的思想是是采用64個基本的ASCII碼字符對數(shù)據(jù)進行重新編碼。它將需要編碼的數(shù)據(jù)拆分成字節(jié)數(shù)組。
    2009-06-06
  • C#使用SQL Dataset數(shù)據(jù)集代碼實例

    C#使用SQL Dataset數(shù)據(jù)集代碼實例

    今天小編就為大家分享一篇關(guān)于的文章,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-10-10
  • C#實現(xiàn)獲取電腦硬件顯卡核心代號信息

    C#實現(xiàn)獲取電腦硬件顯卡核心代號信息

    這篇文章主要為大家詳細介紹了如何利用C#實現(xiàn)獲取電腦硬件顯卡核心代號信息,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2024-01-01
  • C#如何通過RFC連接sap系統(tǒng)

    C#如何通過RFC連接sap系統(tǒng)

    這篇文章主要為大家詳細介紹了C#如何通過RFC連接sap系統(tǒng)的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • C# 根據(jù)表格偶數(shù)、奇數(shù)加載不同顏色

    C# 根據(jù)表格偶數(shù)、奇數(shù)加載不同顏色

    這篇文章主要介紹了C# 根據(jù)表格偶數(shù)、奇數(shù)加載不同顏色,需要的朋友可以參考下
    2017-09-09
  • C#調(diào)用Rar文件及獲取Rar返回值的方法

    C#調(diào)用Rar文件及獲取Rar返回值的方法

    這篇文章主要介紹了C#調(diào)用Rar文件及獲取Rar返回值的方法,實例分析了C#調(diào)用rar文件實現(xiàn)文件的壓縮與解壓相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-07-07

最新評論

平遥县| 左贡县| 新源县| 上饶县| 双桥区| 丰城市| 西昌市| 荥经县| 镇雄县| 万宁市| 福泉市| 郑州市| 本溪市| 晋宁县| 应城市| 栖霞市| 宣武区| 元氏县| 浠水县| 彰化县| 祥云县| 休宁县| 镇坪县| 井冈山市| 徐水县| 旺苍县| 酉阳| 新干县| 雷波县| 通道| 侯马市| 华容县| 宁城县| 泊头市| 五大连池市| 长寿区| 手机| 齐齐哈尔市| 牟定县| 宜君县| 锦屏县|