我必须将特定文件解压缩到特定文件夹
我使用 C# visual studio express 2010 和 dotnetzip 库来压缩
//take the zip file from sftp
Console.WriteLine("Mendownload File va_txn dari KPFS");
Console.WriteLine("===================================");
string remoteDirectory = "/va/";
using (SftpClient sftp = new SftpClient(host, port, username, password))
{
try
{
sftp.Connect();
var fileIn = sftp.ListDirectory(remoteDirectory);
foreach (var file in fileIn)
{
if (!file.Name.Equals(".") && !file.Name.Equals("..") && file.LastWriteTime.Date == DateTime.Today)
{
Console.WriteLine(file.Name);
Console.WriteLine("File ditemukan, selesai dikompress");
//code to download file
using (Stream file1 = File.Create(@"C:Usersu532246DesktopVA" + file.Name))
{
sftp.DownloadFile(remoteDirectory + file.Name, file1);
}
}
}
}
catch
{
}
sftp.Disconnect();
}
//Unzip file
string pathzip = @"C:UsersDesktopVAva_for_copartner_daily.zip";
using (ZipFile zip = new ZipFile())
{
zip.ExtractAll(pathzip);
}
问题是,当解压缩文件代码运行时,解压缩的文件无处可寻,我不知道我丢失了什么或错了什么,也许有人可以帮助我修复我的代码?
您实际上并没有读取 zip 文件,您只是在提取一个空存档,因为您没有为 ZipFile
构造函数提供参数。
这应该这样做:
//Unzip file
string pathzip = @"C:UsersDesktopVAva_for_copartner_daily.zip";
using (ZipFile zip = new ZipFile.Read(pathzip))
{
zip.ExtractAll(@"C:UsersDesktopVASomeOtherFolder");
}