zoukankan      html  css  js  c++  java
  • 文件夹的压缩

       //压缩文件夹下的所有文件及文件夹
            public void ZipFolders(string path, ZipFile zip, int charLength)
            {
                string[] strAry = null;
                strAry = Directory.GetFiles(path);//压缩文件夹下的所有文件不好含文件下的文件夹
                                                  /*****************************初始化时获取当前路径下的所有的文件***************************************************/
                for (int i = 0; i < strAry.Length; i++)
                {
                    string parent = path.Substring(charLength);//截取出来时没有盘符
                    //第一个参数文件的物理路径,第二个参数是虚拟路径(压缩包中的路径)不要盘符的路径。test就是文件夹文件名称
                    zip.Add(strAry[i], parent + "\" + new FileInfo(strAry[i]).Name);
                }
                /*****************************初始化时获取当前路径下的当前的文件夹***************************************************/
                string[] strDirectories = Directory.GetDirectories(path);
                for (int i = 0; i < strDirectories.Length; i++)
                {
                    ZipFolders(strDirectories[i], zip, charLength);//递归
                }
            }
     DialogResult result = this.folderBrowserDialog2.ShowDialog();
                if (result == DialogResult.OK)
                {
                  string path =this.folderBrowserDialog2.SelectedPath;
                    using (ZipFile zip = ZipFile.Create(@"E: est3.rar"))
                    {
                        zip.BeginUpdate();
                      //  string path = @"E:其他";
                        ZipFolders(path, zip, path.LastIndexOf('\') + 1);//E:\
                        zip.CommitUpdate();
                    }
                }
  • 相关阅读:
    LeetCode59 Spiral Matrix II
    LeetCode58 Length of Last Word
    LeetCode54 Spiral Matrix
    LeetCode63 Unique Paths II
    LeetCode62 Unique Paths
    LeetCode55 Jump Game
    网易2017年校招笔试题 最大的奇约数
    Codeforces Round #119 (Div. 2)
    Codeforces Round #118 (Div. 2)
    2016 MIPT Pre-Finals Workshop Taiwan NTU Contest
  • 原文地址:https://www.cnblogs.com/GuoLianSheng/p/13223607.html
Copyright © 2011-2022 走看看