网上一搜都是压缩一个文件的。
文件侠怎么压缩。
比如A目录下,有B,C目录,要压缩A目录成A.zip
文件侠怎么压缩。
比如A目录下,有B,C目录,要压缩A目录成A.zip
解决方案 »
- 一个查询异常,55分。
- C#中UNICODE字符如何转换成ANSI
- Counts = Convert.ToInt32(command.ExecuteScalar()) 提示确保参数格式正确 怎么改
- 使用C#做一个统计报表,高手进来看看
- 打印页位置不准确 C#
- 请教大家怎么编写ListView的拖拽事件
- 在asp.net里面,怎么实现与在页面中 右键->刷新 功能等同的代码?
- 请 RainAndFire 过来,给您另加20分
- 《Ado.net技术内幕》这本书是用什么语言描述的 c# 还是 vb?望读过的高手指点
- 使用参数化sql语句新增记录,提示语法错误,如何排查原因?
- treeView 加载的数据多时,能否将滚动条的位置放到最上面,并选择树形菜单的第一个节点(C/S结构)
- 请教一个VS2003升级到VS2005后ActiveX的问题,急求帮助,谢谢!
{
public string file;
public ZipDAO(string dir)
{
Console.WriteLine("开始压缩.....");
file = dir;
} public void ZipFold()
{
//获得压缩的文件夹
//压缩文件夹的名字
string name = file + ".rar";
//压缩文件的流对象
// MessageBox.Show(name);
ZipOutputStream output = new ZipOutputStream(File.Create(name));
output.SetLevel(6);
string[] dir = Directory.GetFiles(file);
//存放文件数据
Crc32 crc = new Crc32();
foreach (string myFile in dir)
{
FileStream fs = new FileStream(myFile, FileMode.Open, FileAccess.Read);
byte[] bt = new byte[fs.Length];
fs.Read(bt, 0, bt.Length);
//存储要压缩的文件
ZipEntry entry = new ZipEntry(myFile.Substring(myFile.Length - 41, 41));
entry.Size = fs.Length;
entry.DateTime = DateTime.Now;
fs.Close();
crc.Reset(); //清除crc内容
crc.Update(bt); //更新文件内容到crc中
entry.Crc = crc.Value; //将文件内容放到压缩文件中
output.PutNextEntry(entry);
//将数据写入压缩流中
output.Write(bt, 0, bt.Length);
}
output.Close();
Console.WriteLine("压缩成功!");
}
}
{
public string file;
public ZipDAO(string dir)
{
Console.WriteLine("开始压缩.....");
file = dir;
} public void ZipFold()
{
//获得压缩的文件夹
//压缩文件夹的名字
string name = file + ".rar";
//压缩文件的流对象
// MessageBox.Show(name);
ZipOutputStream output = new ZipOutputStream(File.Create(name));
output.SetLevel(6);
string[] dir = Directory.GetFiles(file);
//存放文件数据
Crc32 crc = new Crc32();
foreach (string myFile in dir)
{
FileStream fs = new FileStream(myFile, FileMode.Open, FileAccess.Read);
byte[] bt = new byte[fs.Length];
fs.Read(bt, 0, bt.Length);
//存储要压缩的文件
ZipEntry entry = new ZipEntry(myFile.Substring(myFile.Length - 41, 41));
entry.Size = fs.Length;
entry.DateTime = DateTime.Now;
fs.Close();
crc.Reset(); //清除crc内容
crc.Update(bt); //更新文件内容到crc中
entry.Crc = crc.Value; //将文件内容放到压缩文件中
output.PutNextEntry(entry);
//将数据写入压缩流中
output.Write(bt, 0, bt.Length);
}
output.Close();
Console.WriteLine("压缩成功!");
}
}