2
我正在使用庫ICSharpCode.SharpZipLib.Zip
;在zip中使用ICSharpCode.SharpZipLib.Zip子文件夾時,它不應該是
我的代碼如下:
- 的路徑是根。
\\ALAWP\\THIS\\ACORD\\
- 我他們荏苒到
ZIPDirectory
但是當它完成該文件未命名acord_combined.txt
,而不是它被稱爲ACORD\acord_combined.txt
我在做什麼錯?
public void CleanRoot()
{
DirectoryInfo RootDi = new DirectoryInfo(FilePrep.RootDirectory);
string ZipDirectory = FilePrep.RootDirectory + "\\processed\\AceKey"+ DateTime.Now.ToString("yyyyMMdd_H;mm;ss") +".zip";
ZipOutputStream NewZipOutput = new ZipOutputStream(File.Create(ZipDirectory));
foreach (FileInfo fi in RootDi.GetFiles("acord*.*"))
{
Compress(ref NewZipOutput, fi);
//MoveFile(fi.FullName,ZipDirectory);
}
NewZipOutput.Finish();
NewZipOutput.Close();
}
public void Compress(ref ZipOutputStream ZipFolder, FileInfo fi)
{
try
{
FileStream fsFileToBeZipped = fi.OpenRead();
ZipEntry entry = new ZipEntry(fi.FullName);
ZipFolder.PutNextEntry(entry);
int size = 2048;
byte[] buffer = new byte[size];
while (true)
{
size = fsFileToBeZipped.Read(buffer, 0, buffer.Length);
if (size > 0)
ZipFolder.Write(buffer, 0, size);
else
break;
} //end while (true)
fsFileToBeZipped.Close();
//prepare and delete file
fi.Attributes = FileAttributes.Normal;
//fi.Delete();
} //end try
catch (Exception e)
{
Console.WriteLine("Error zipping File. Error - " + e.Message);
} //end catch
}
或者你可以只使用fi.Name來獲取名稱和文件擴展名。確切地說, – 2012-04-05 20:34:14
。一般來說,第一個參數是指定文件名在檔案中的顯示方式。 – devshorts 2012-04-05 20:35:38
工作就像一個魅力!謝謝。 – 2012-04-05 21:07:53