C# 如何在zip文件中修改文件属性?
使用SharpZipLib,我将文件添加到现有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);
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));
}