2015-02-18 4 views
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 файла.
Но, к сожалению, я понял, что это возможно только при создании нового файла почтового индекса, используя ZipOutputStream и установить ExternalFileAttributes:

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

Есть ли способ, чтобы добавить файлы и изменять атрибуты файлов?

Возможно ли это с помощью DotNetZip?

ответ

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

прекрасно работает ...