(C#)文件操作--解压文件夹和文件
2011-01-10 15:35
295 查看
using ICSharpCode.SharpZipLib.Zip;
using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
namespace DataReportedFeedBack
{
public class UnZipClass
{
public void UnZip(string[] args)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(args[1]);
string fileName = Path.GetFileName(theEntry.Name);
//生成解压目录
// create directory
if (directoryName != "")
{
Directory.CreateDirectory(directoryName);
}
if (fileName != String.Empty)
{
//if (theEntry.Name.IndexOf(".ini") < 0)
//{
string fullPath = directoryName + "//" + theEntry.Name;
fullPath = fullPath.Replace("// ", "//");
string fullDirPath = Path.GetDirectoryName(fullPath);
if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
FileStream streamWriter = File.Create(fullPath);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
//}
}
}
s.Close();
}
}
}
调用:
private void button3_Click(object sender, EventArgs e)
{
string[] FileProperties = new string[2];
待解压的文件
FileProperties[0] = strToBak1Directory + "//" + f.Name;
解压后放置的目标目录
FileProperties[1] = strTempDiretory+"//";
UnZipClass UnZc = new UnZipClass();
UnZc.UnZip(FileProperties);
}
using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
namespace DataReportedFeedBack
{
public class UnZipClass
{
public void UnZip(string[] args)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(args[1]);
string fileName = Path.GetFileName(theEntry.Name);
//生成解压目录
// create directory
if (directoryName != "")
{
Directory.CreateDirectory(directoryName);
}
if (fileName != String.Empty)
{
//if (theEntry.Name.IndexOf(".ini") < 0)
//{
string fullPath = directoryName + "//" + theEntry.Name;
fullPath = fullPath.Replace("// ", "//");
string fullDirPath = Path.GetDirectoryName(fullPath);
if (!Directory.Exists(fullDirPath)) Directory.CreateDirectory(fullDirPath);
FileStream streamWriter = File.Create(fullPath);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
//}
}
}
s.Close();
}
}
}
调用:
private void button3_Click(object sender, EventArgs e)
{
string[] FileProperties = new string[2];
待解压的文件
FileProperties[0] = strToBak1Directory + "//" + f.Name;
解压后放置的目标目录
FileProperties[1] = strTempDiretory+"//";
UnZipClass UnZc = new UnZipClass();
UnZc.UnZip(FileProperties);
}
相关文章推荐
- C# 压缩 解压 复制文件夹,文件的操作
- c# asp.net 读取 写入 操作 文件、文件夹(大全系列)
- C# 文件操作 全收录 追加、拷贝、删除、移动文件、创建目录、递归删除文件夹及文件....
- C#文件及文件夹的操作
- C# 文件操作(全部) 追加、拷贝、删除、移动文件、创建目录 修改文件名、文件夹名
- C#压缩解压文件及文件夹Helper
- C# 文件操作 全收录 追加、拷贝、删除、移动文件、创建目录、递归删除文件夹及文件
- C# 常用文件及文件夹操作
- C# IO操作,文件 文件夹
- C#文件夹和文件操作
- C#文件夹及文件操作(检查 创建 读取 写入 修改 删除)
- C#文件操作源码 递归复制一个目录 递归删除文件 和 文件夹
- C# 对文件与文件夹的操作包括删除、移动与复制
- 【转】C# 文件操作 全收录 追加、拷贝、删除、移动文件、创建目录、递归删除文件夹及文件....
- c#解压压缩文件和文件夹
- C#利用SharpZipLib解压或压缩文件夹实例操作
- C#对文件/文件夹操作代码汇总
- C#对文件操作(基本的读写以及压缩和解压)
- C#文件操作源码 递归复制一个目录 递归删除文件 和 文件夹
- C#文件和文件夹操作