icsharpcode.texteditor怎么折叠
1个回答
展开全部
代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; using System.IO; using ICSharpCode.SharpZipLib.Zip; using System.Text.RegularExpressions; namespace MyTest { public static class StartZip { public static void Run(string rootDirectory, string zipFileName, params string[] fileOrDirectory) { if (fileOrDirectory == null || fileOrDirectory.Length < 一) return; Regex reg一 = new Regex(@"[a-z]:$", RegexOptions.IgnoreCase); Match math一 = reg一.Match(rootDirectory); if (math一.Success) { rootDirectory =math一.Value+@"\"; } int zipLevel = 陆; string fullZipFileName = rootDirectory + zipFileName + ".zip"; for (int count = 0; count < fileOrDirectory.Length; count++) { string str = fileOrDirectory[count]; if (str.EndsWith("\\")) { str = str.Substring(0, str.Length - 一); } str = str.Substring(0, str.LastIndexOf("\\")); Zip(fullZipFileName, str, zipLevel, fileOrDirectory); } } private static void Zip(string fullZipFileName, string currentDirectory, int zipLevel, params string[] fileOrDirectory) { ArrayList AllFiles = new ArrayList(); //AllFiles:存储具体文件路径容器 if (fileOrDirectory != null) { for (int i = 0; i < fileOrDirectory.Length; i++) { if (File.Exists(fileOrDirectory[i])) { AllFiles.Add(fileOrDirectory[i]); } else if (Directory.Exists(fileOrDirectory[i])) { GetDirectoryFile(fileOrDirectory[i], AllFiles); } } } if (AllFiles.Count < 一) return; ZipOutputStream zipedStream = new ZipOutputStream(File.Create(fullZipFileName)); //ZipOutputStreamnew初始化:创建应zipFileName文件名Zip文件 zipedStream.SetLevel(zipLevel); for (int i = 0; i < AllFiles.Count; i++) { string file = AllFiles[i].ToString(); FileStream fs; fs = File.OpenRead(file); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); //新建entry string fileName = file.Replace(currentDirectory, ""); if (fileName.StartsWith("\\")) { fileName = fileName.Substring(一); } ZipEntry entry = new ZipEntry(fileName); entry.DateTime = DateTime.Now; fs.Close(); zipedStream.PutNextEntry(entry); zipedStream.Write(buffer, 0, buffer.Length); fs.Close(); fs.Dispose(); } zipedStream.Finish(); zipedStream.Close(); } private static void GetDirectoryFile(string parentDirectory, ArrayList toStore) //递归获取目录所文件 { string[] files = Directory.GetFiles(parentDirectory); //Directory.GetFiles (String):返指定目录文件名称(包括其路径); for (int i = 0; i < files.Length; i++) { toStore.Add(files[i]); } string[] directorys = Directory.GetDirectories(parentDirectory); //Directory.GetDirectories (String):获取指定目录目录名称(包括其路径) //目录即文件夹; for (int i = 0; i < directorys.Length; i++) { GetDirectoryFile(directorys[i], toStore); } } }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询