11

ICSharpCode.SharpZipLib.Zip.FastZipファイルを圧縮するために使用していますが、問題が発生しています。

ファイル名に特殊文字を含むファイルを圧縮しようとすると、機能しません。ファイル名に特殊文字が含まれていない場合に機能します。

4

5 に答える 5

10

FastZip は使用できないと思います。ファイルを繰り返し、次のように指定して自分でエントリを追加する必要があります。

entry.IsUnicodeText = true;

エントリがユニコードであることを SharpZipLib に伝えます。

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();
 }
于 2011-03-26T08:55:07.483 に答える
4

必要に応じて引き続き使用できますが、で を作成するFastZipを与える必要があります。ZipEntryFactoryZipEntryIsUnicodeText = true

var zfe = new ZipEntryFactory { IsUnicodeText = true };
var fz = new FastZip { EntryFactory = zfe };
fz.CreateZip("out.zip", "C:\in", true, null);
于 2015-08-27T18:32:32.267 に答える
1

使用できるように、SharpZipLib ライブラリの最新バージョンをダウンロードしてコンパイルする必要があります。

entry.IsUnicodeText = true;

ここにあなたのスニペットがあります(わずかに変更されています):

FileInfo file = new FileInfo("input.ext");
using(var sw = new FileStream("output.zip", FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
    using(var zipStream = new ZipOutputStream(sw))
    {
        var entry = new ZipEntry(file.Name);
        entry.IsUnicodeText = true;
        zipStream.PutNextEntry(entry);

        using (var reader = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
        {
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = reader.Read(buffer, 0, buffer.Length)) > 0)
            {
                byte[] actual = new byte[bytesRead];
                Buffer.BlockCopy(buffer, 0, actual, 0, bytesRead);
                zipStream.Write(actual, 0, actual.Length);
            }
        }
    }
}
于 2012-12-20T09:17:21.147 に答える
0

ファイル名から特殊文字を削除してみてください。つまり、置き換えてください。君のFilename.Replace("&", "&");

于 2011-04-27T09:47:08.417 に答える
0

可能性 1: 正規表現ファイル フィルターにファイル名を渡しています。

可能性 2: これらの文字は zip ファイルでは許可されていません (または、少なくとも SharpZipLib はそう考えています)。

于 2010-11-22T19:22:23.167 に答える