0

SharpZipLib を使用して、既存の zip ファイルにファイルを追加しています。

        using (ZipFile zf = new ZipFile(zipFile)) {
            zf.BeginUpdate();
            foreach (FileInfo fileInfo in fileInfos) {
                string name = fileInfo.FullName.Substring(rootDirectory.Length);
                FileAttributes attributes = fileInfo.Attributes;
                if (clearArchiveAttribute) attributes &= ~FileAttributes.Archive;

                zf.Add(fileInfo.FullName, name);
//TODO: Modify file attribute?
            }
            zf.CommitUpdate();
            zf.Close();
        }

ここでのタスクは、Archiveファイル属性をクリアすることです。
しかし残念ながら、これはZipOutputStreamand setを使用して新しい zip ファイルを作成する場合にのみ可能であることがわかりましたExternalFileAttributes

            // ...
            ZipEntry entry = new ZipEntry(name);
            entry.ExternalFileAttributes = (int)attributes;
            // ...

ファイルを追加してファイル属性を変更する方法はありますか?

これは DotNetZip で可能ですか?

4

1 に答える 1

0

SharpZipLib のソースが利用可能であるため、ZipFile.Add自分で別のオーバーロードを追加しました。

    public void Add(string fileName, string entryName, int attributes) {
        if (fileName == null) {
            throw new ArgumentNullException("fileName");
        }

        if (entryName == null) {
            throw new ArgumentNullException("entryName");
        }

        CheckUpdating();
        ZipEntry entry = EntryFactory.MakeFileEntry(entryName);
        entry.ExternalFileAttributes = attributes;
        AddUpdate(new ZipUpdate(fileName, entry));
    }

よく働く...

于 2015-02-19T07:22:56.377 に答える