Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在zip文件中修改文件属性?_C#_Windows_Sharpziplib_File Attributes - Fatal编程技术网

C# 如何在zip文件中修改文件属性?

C# 如何在zip文件中修改文件属性?,c#,windows,sharpziplib,file-attributes,C#,Windows,Sharpziplib,File Attributes,使用SharpZipLib,我将文件添加到现有zip文件中: using (ZipFile zf = new ZipFile(zipFile)) { zf.BeginUpdate(); foreach (FileInfo fileInfo in fileInfos) { string name = fileInfo.FullName.Substring(rootDirectory.Length);

使用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();
        }
现在的任务是清除归档文件属性。 但不幸的是,我发现只有在使用ZipOutStream创建新的zip文件并设置ExternalFileAttributes时,才有可能做到这一点:

是否有添加文件和修改文件属性的方法


DotNetZip是否可以实现这一点?

由于SharpZipLib的源代码可用,我添加了另一个ZipFile重载。我自己添加:

    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));
    }
工作很好

    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));
    }