文件夹压缩代码 private void dlZipDir() // string strPath, string strFileName) { string strPath = @"C:\Documents and Settings\wuy\桌面"; String strBaseDir = ""; //MemoryStream ms = null; //ms = new MemoryStream(); //zos = new ZipOutputStream(ms); zos = new ZipOutputStream(File.Create(outname)); strBaseDir = strPath + "\\"; addZipEntry(strBaseDir); zos.Finish(); zos.Close(); } private void addZipEntry( string PathStr) { DirectoryInfo di = new DirectoryInfo(PathStr); foreach (DirectoryInfo item in di.GetDirectories()) { addZipEntry(item.FullName); } foreach (FileInfo item in di.GetFiles()) { FileStream fs = File.OpenRead(item.FullName); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); string strEntryName = item.FullName.Replace("aa", ""); ZipEntry entry = new ZipEntry(strEntryName); zos.PutNextEntry(entry); zos.Write(buffer, 0, buffer.Length); fs.Close(); } } posted on 2006-11-07 16:03 吴勇 阅读( ...) 评论( ...) 编辑 收藏 转载于:https://www.cnblogs.com/wuyong/archive/2006/11/07/553050.html