Batch rename files inside zips

As the title suggest I am looking for some examples that will let me batch rename files inside of zip files...

here is an example of what I would like to do ....

1. Load the zip (sample.zip)

Contents of the zip look like this:

andna.jpg
anoiun.jpg
e89bo.jpg
33nnt.jpg
ffe9n.jpg

2. Press a button and have the above files renamed like this:

sample_01.jpg
sample_02.jpg
sample_03.jpg
sample_04.jpg
sample_05.jpg

I have at my disposal the Abbrevia components from Turbo Power and the Zip Master components so an example from either of those will be fine and I will award 200 extra points if you provide code that will allow me to recursively go through a directory of zips and do the task above to each of them.

TIA,
Pete
ezpeteAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gandalf_the_whiteCommented:
quite dirty but working:
you could extract the files, rename them and then pack them again

regards
0
ezpeteAuthor Commented:
I could do that manually so no thx...
0
Eddie ShipmanAll-around developerCommented:
ezpete, you could do it progamatically, too, using TPAbbreva or some other Zip control.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

gandalf_the_whiteCommented:
that was what i meant
most packer have a commandline interface so you could extract and repack the files via commandline parameters
0
ezpeteAuthor Commented:
My point was that the Abbrevia component has a "move" function which allows you to rename a file in a zip without extracting it first and I can do it  one file at at time but I am looking for a way to do it to ALL the files in the zip in one shot and as I said in my original post I am looking for examples not just  methods.

I don't want to sound greedy but for a possible 400 points it's worth more then a suggestion.

TIA,
Pete
0
Eddie ShipmanAll-around developerCommented:
Well, you are going to have to do it in a loop no matter how you do it because there is
no way to progromatically rename them in sequential order without one.

I'll try to whip something up for you in the next couple hours.
0
Eddie ShipmanAll-around developerCommented:
Try this:

{ZP is a TAbZipper control}
procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
  ext: String;
begin
  ZP.OpenArchive('c:\ZP1.zip');
  for i := 0 to ZP.ZipArchive.Count - 1 do
  begin
    ext := ExtractFileExt(ZP.Items[i].FileName);
    if ext <> '' then
    begin
      ZP.Move(ZP.Items[i], ZP.Items[i].DiskPath + 'archiveitem_'+IntToStr(i)+ ext);
    end
    end;
  end;
  ZP.Save;
end;

This does take into consideration DIRECTORIES within the zip file.

It took <1 sec for a zip file with 82 items.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ezpeteAuthor Commented:
Funny I tried pretty much the exact same thing and only got the first file in the archive to change... Anyway I can either award you 200 points for the reply thus far and close the question or if you would like to take a stab at doing the same thing with a directory of zips then I will award you 400 points it's up to you.
0
ezpeteAuthor Commented:
Nvm I  got it to work on a directory of zips ... thx for helping out.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.