?
Solved

Batch rename files inside zips

Posted on 2004-11-07
9
Medium Priority
?
343 Views
Last Modified: 2010-04-05
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
0
Comment
Question by:ezpete
  • 4
  • 3
  • 2
9 Comments
 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 12522813
quite dirty but working:
you could extract the files, rename them and then pack them again

regards
0
 

Author Comment

by:ezpete
ID: 12522903
I could do that manually so no thx...
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 12528500
ezpete, you could do it progamatically, too, using TPAbbreva or some other Zip control.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:gandalf_the_white
ID: 12530598
that was what i meant
most packer have a commandline interface so you could extract and repack the files via commandline parameters
0
 

Author Comment

by:ezpete
ID: 12537292
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
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 12538112
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
 
LVL 26

Accepted Solution

by:
Eddie Shipman earned 800 total points
ID: 12539540
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
 

Author Comment

by:ezpete
ID: 12539937
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
 

Author Comment

by:ezpete
ID: 12545538
Nvm I  got it to work on a directory of zips ... thx for helping out.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question