I have a compressed file .rar .7z, .tar and .zip and I want to rename physical file name available in above compressed archived using C#.
I have tried this using a sharpcompress library but I can't find such a feature for rename file or folder name within .rar .7z, .tar and .zip file.
I also have tried using the DotNetZip library but its only support.Zip she what I tried using DotNetZip library.
- private static void RenameZipEntries(string file)
- {
- try
- {
- int renameCount = 0;
- using (ZipFile zip2 = ZipFile.Read(file))
- {
-
- foreach (ZipEntry e in zip2.ToList())
- {
- if (!e.IsDirectory)
- {
- if (e.FileName.EndsWith(".txt"))
- {
- var newname = e.FileName.Split('.')[0] + "_new." + e.FileName.Split('.')[1];
- e.FileName = newname;
- e.Comment = "renamed";
- zip2.Save();
- renameCount++;
- }
- }
- }
- zip2.Comment = String.Format("This archive has been modified. {0} files have been renamed.", renameCount);
- zip2.Save();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
-
- }
But actually the same as above I also want for .7z, .rar and .tar, I tried many libraries but still I didn't get any accurate solution.
Please help me.