(C#)winform中实现选择一个文件夹,将其压缩复制到另外一个路径

第三行代码 2010-04-23 02:36:20
(C#)winform中实现选择一个文件夹,将其压缩复制到另外一个路径

请教各位了。
...全文
227 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
skep99 2010-04-23
  • 打赏
  • 举报
回复
//单个文件创建zip文件
public static string createZipfile(string path)
{
int m = 1;//块大小,单位兆
try
{
Crc32 crc = new Crc32();
ZipOutputStream zipout = new ZipOutputStream(File.Create(path + ".zip"));
FileStream fs = File.OpenRead(path);
long pai = 1024 * 1024 * m;//每m兆写一次
long forint = fs.Length / pai + 1;
byte[] buffer = null;
ZipEntry entry = new ZipEntry(Path.GetFileName(path));
entry.Size = fs.Length;
entry.DateTime = DateTime.Now;
zipout.PutNextEntry(entry);

for (long i = 1; i <= forint; i++)
{
if (pai * i < fs.Length)
{
buffer = new byte[pai];
fs.Seek(pai * (i - 1), SeekOrigin.Begin);
}
else
{
if (fs.Length < pai)
{
buffer = new byte[fs.Length];
}
else
{
buffer = new byte[fs.Length - pai * (i - 1)];
fs.Seek(pai * (i - 1), SeekOrigin.Begin);
}
}
fs.Read(buffer, 0, buffer.Length);
crc.Reset();
crc.Update(buffer);
zipout.Write(buffer, 0, buffer.Length);
zipout.Flush();
}
//this.byteFile = buffer;
fs.Close();
zipout.Finish();
zipout.Close();
//File.Delete(path); //删除原文件
return path + ".zip";
}
catch (Exception ex)
{
string str = ex.Message;
return path;
}
}
nbhx2010 2010-04-23
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhujiazhi 的回复:]

ICSharpCode.SharpZipLib.dll
[/Quote]

顶这个
zhujiazhi 2010-04-23
  • 打赏
  • 举报
回复
ICSharpCode.SharpZipLib.dll
xshf12345 2010-04-23
  • 打赏
  • 举报
回复
参考http://www.fly010.net/new1957.html
xshf12345 2010-04-23
  • 打赏
  • 举报
回复
如果加分的话,我可以写好了发给你,呵呵

111,096

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧