国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

文件夾和文件壓縮

2019-11-14 10:04:18
字體:
供稿:網(wǎng)友
        ///<summary>        ///功能:壓縮文件(暫時只壓縮文件夾下一級目錄中的文件,文件夾及其子級被忽略)        ///</summary>        ///<paramname="dirPath">被壓縮的文件夾夾路徑</param>        ///<paramname="zipFilePath">生成壓縮文件的路徑,為空則默認與被壓縮文件夾同一級目錄,名稱為:文件夾名+.zip</param>        ///<paramname="err">出錯信息</param>        ///<returns>是否壓縮成功</returns>        publicboolZipFile(string dirPath,stringzipFilePath,outstringerr)        {           err = "";            if(dirPath == string.Empty)            {               err = "要壓縮的文件夾不能為空!";               return false;            }            if(!Directory.Exists(dirPath))            {               err = "要壓縮的文件夾不存在!";               return false;            }            //壓縮文件名為空時使用文件夾名+.zip            if(zipFilePath == string.Empty)            {               if (dirPath.EndsWith("//"))               {                   dirPath = dirPath.Substring(0, dirPath.Length - 1);               }               zipFilePath = dirPath + ".zip";            }             try            {               string[] filenames =Directory.GetFiles(dirPath);               using (ZipOutputStreams =newZipOutputStream(File.Create(zipFilePath)))               {                   s.SetLevel(9);                   byte[] buffer =newbyte[4096];                   foreach (stringfilein filenames)                   {                        ZipEntry entry =newZipEntry(Path.GetFileName(file));                        entry.DateTime = DateTime.Now;                        s.PutNextEntry(entry);                        using(FileStream fs =File.OpenRead(file))                        {                            intsourceBytes;                            do                            {                                sourceBytes =fs.Read(buffer, 0, buffer.Length);                                s.Write(buffer,0, sourceBytes);                            } while(sourceBytes > 0);                        }                   }                   s.Finish();                   s.Close();               }            }            catch(Exception ex)            {               err = ex.Message;               return false;            }            returntrue;        }
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 五家渠市| 博爱县| 固镇县| 井冈山市| 明光市| 浦东新区| 和硕县| 太和县| 江永县| 台湾省| 吉木萨尔县| 于都县| 永春县| 巴林左旗| 象山县| 长宁县| 滦平县| 饶平县| 剑川县| 仪陇县| 石渠县| 奎屯市| 柳河县| 府谷县| 衡南县| 科技| 浙江省| 城市| 营山县| 宜宾县| 马鞍山市| 牡丹江市| 云霄县| 康乐县| 新野县| 米林县| 贵南县| 石首市| 呈贡县| 神木县| 潢川县|