Vote count:
0
I use simple c# code for update archive:
using (var zip = ZipFile.Open(archive, ZipArchiveMode.Update, Encoding.UTF8))
{
var directories = new DirectoryInfo(folder);
var files = directories
.GetFiles("*", SearchOption.TopDirectoryOnly)
.Select(f => f.FullName)
.Except(directories
.GetFiles(ArchivePattern, SearchOption.TopDirectoryOnly)
.Select(f => f.FullName));
foreach (var file in files)
{
var fileName = file
.Replace(directories.FullName + Path.DirectorySeparatorChar, string.Empty)
.Replace(directories.FullName, string.Empty);
var fileInZip = zip.Entries.FirstOrDefault(f => f.FullName == fileName);
if (fileInZip != null)
fileInZip.Delete();
zip.CreateEntryFromFile(file, fileName, CompressionLevel.NoCompression);
}
}
But, another user say, he lost all new files (all packed files deleted after this code). And in archive only old files.
I dont have any idea, when i lost files. Want any idea, how to improve code or what library\methods can help with this.
asked 12 secs ago
New files not added to archive, when i update it
Aucun commentaire:
Enregistrer un commentaire