ICSharpCode.SharpZipLib.Zip.FastZip不压缩文件名中包含特殊字符的文件

Bre*_*ead 9 .net c# sharpziplib

ICSharpCode.SharpZipLib.Zip.FastZip用来压缩文件,但我遇到了问题:

当我尝试压缩文件名中包含特殊字符的文件时,它不起作用.当文件名中没有特殊字符时,它可以工作.

Paa*_*and 6

我想你不能使用FastZip.您需要迭代文件并自己添加条目,指定:

entry.IsUnicodeText = true;

告诉SharpZipLib,条目是unicode.

string[] filenames = Directory.GetFiles(sTargetFolderPath);

// Zip up the files - From SharpZipLib Demo Code
using (ZipOutputStream s = new
    ZipOutputStream(File.Create("MyZipFile.zip")))
{
    s.SetLevel(9); // 0-9, 9 being the highest compression

    byte[] buffer = new byte[4096];

    foreach (string file in filenames)
    {
         ZipEntry entry = new ZipEntry(Path.GetFileName(file));

         entry.DateTime = DateTime.Now;
         entry.IsUnicodeText = true;
         s.PutNextEntry(entry);

         using (FileStream fs = File.OpenRead(file))
         {
             int sourceBytes;
             do
             {
                 sourceBytes = fs.Read(buffer, 0, buffer.Length);

                 s.Write(buffer, 0, sourceBytes);

             } while (sourceBytes > 0);
         }
    }
    s.Finish();
    s.Close();
 }
Run Code Online (Sandbox Code Playgroud)


bla*_*iet 5

FastZip如果您愿意,您可以继续使用,但您需要给它一个ZipEntryFactory创建ZipEntrys 的IsUnicodeText = true

var zfe = new ZipEntryFactory { IsUnicodeText = true };
var fz = new FastZip { EntryFactory = zfe };
fz.CreateZip("out.zip", "C:\in", true, null);
Run Code Online (Sandbox Code Playgroud)


Jos*_*hua 0

可能性 1:您将文件名传递给正则表达式文件过滤器。

可能性 2:zip 文件中不允许使用这些字符(或者至少 SharpZipLib 是这么认为的)