TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Nikunj Satasiya
193
10k
3.7m
How to Rename Files and Folder in .rar .7z, .tar, .zip using
Dec 23 2019 12:38 AM
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.
Reply
Answers (
1
)
Error in response.redirect
How could I split in RegularExpressions ?