Rename .zip folder using filename of a file within

Post any general comments regarding Bulk Rename Utility here. Open to all registered users.

Rename .zip folder using filename of a file within

Postby gbfromsd » Fri Mar 03, 2017 3:02 am

I have 40000 files to rename and BRU seems to me to be the ticket, if only I could figure this out.
I have a list of zip files in the format FILE19854.ZIP, FILE19855.ZIP, etc.
Contained within each are two files, let's say 14001 - Biscuit.mp3, and 14001 - Biscuit.txt
The mp3 filenames in each individual ZIP file vary, and these names are of varying lengths.
I need to rename each .zip folder in this example as 14001 - Biscuit.ZIP which would still contain
the original two files.

Can anyone point me in a direction or to a similar previous post?

Posts: 1
Joined: Fri Mar 03, 2017 2:42 am

Re: Rename .zip folder using filename of a file within

Postby therube » Mon Mar 06, 2017 5:48 pm

I need to rename each .zip folder

When you're saying "folder", you're actually meaning the ZIP (archive) file name?
So you want to rename the ZIP name?

(And not do something like extract the contents of each ZIP into a folder named with the same name as the ZIP's contents.)
Posts: 317
Joined: Mon Jan 18, 2016 6:23 pm

Re: Rename .zip folder using filename of a file within

Postby therube » Mon Mar 06, 2017 7:25 pm

Pseudo-code (oh, this is gonna be ugly...)

(Always work from a backup)

Assuming a single directory tree with 40K ZIPs...
Also assumes that each ZIP contains only a single .mp3 (& associated .txt)
(That's quite a number, wonder if BRU would even handle all them at once...)

Prefix ; Start 1 ; Incr 1 ; Pad 5

That should give you files named:


Create a subdirectory named, X.
Extract those 40K into individually named directories (with a single subdirectory)

7-zip.exe -x *.ZIP -oX*

(extract file contents into a same named directory
& you end up with something like this:)

Lumpy Gravy.mp3
Lumpy Gravy.txt
Simple Man.mp3
Simple Man.txt
Extract all the ZIP into same named directories


The file DIRS will have a listing of your 40K directory names

List all mp3 file names, output to a file named "MP3"
ls.exe -R | grep.exe -i .mp3 > MP3

Lumpy Gravy.mp3
Simple Man.mp3

paste DIRS MP3 > OUT
copy the two files, line by line, side by side, output to a file named, OUT

00001<TAB>Lumpy Gravy.mp3
40000<TAB>Simple Man.mp3

Edit the file OUT, substitute <TAB> with a '|'

sed "s/\t/|/" > BAR.txt

00001|Lumpy Gravy.mp3
40000|Simple Man.mp3

Bulk Rename Utility
Actions | Import Rename-Pairs... ---> BAR.txt

With that, it should then show the (directory) renames to be:
00001 ---> Lumpy Gravey.mp3
40000 ---> Simple Man.mp3

Rename them.

The directories should now be name, & have files within:
Lumpy Gravy.mp3
|->Lumpy Gravy.mp3
|->Lumpy Gravy.txt
Simple Man.mp3
|->Simple Man.mp3
|->Simple Man.txt

Rename the directories, removing the .mp3
Lumpy Gravy <DIR>
Simple Man <DIR>

ZIP each of those directories back into individual ZIPs.
for /d %X in (*) do 7-zip.exe a "" "%X\"



Heh, something like that might work.
There's probably an easier way ;-). (paste.exe & ls.exe, among others)
Posts: 317
Joined: Mon Jan 18, 2016 6:23 pm

Return to General Comments