#region ZipFiles
public static bool ZipFiles(string[] fileNames, string outZipFileName)
{
bool flag = false;
try
{
Crc32 crc = new Crc32();
ZipOutputStream s = new ZipOutputStream(System.IO.File.Create(outZipFileName));
s.SetLevel(6); // 0 - store only to 9 - means best compression
foreach (string file in fileNames)
{
FileStream fs = System.IO.File.OpenRead(file);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
entry.DateTime = DateTime.Now;
// set Size and the crc, because the information
// about the size and crc should be stored in the header
// if it is not set it is automatically written in the footer.
// (in this case size == crc == -1 in the header)
// Some ZIP programs have problems with zip files that don't store
// the size and crc in the header.
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
}
s.Finish();
s.Close();
flag = true;
}
catch
{
}
return flag;
}
这是C#.net编的一个文件压缩过程,请问哪位高手可知要把整个文件夹全部打包压缩(包括子目录和文件)
public static bool ZipFiles(string[] fileNames, string outZipFileName)
{
bool flag = false;
try
{
Crc32 crc = new Crc32();
ZipOutputStream s = new ZipOutputStream(System.IO.File.Create(outZipFileName));
s.SetLevel(6); // 0 - store only to 9 - means best compression
foreach (string file in fileNames)
{
FileStream fs = System.IO.File.OpenRead(file);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
entry.DateTime = DateTime.Now;
// set Size and the crc, because the information
// about the size and crc should be stored in the header
// if it is not set it is automatically written in the footer.
// (in this case size == crc == -1 in the header)
// Some ZIP programs have problems with zip files that don't store
// the size and crc in the header.
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
}
s.Finish();
s.Close();
flag = true;
}
catch
{
}
return flag;
}
这是C#.net编的一个文件压缩过程,请问哪位高手可知要把整个文件夹全部打包压缩(包括子目录和文件)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货