Page 1 of 1

Rename .zip folder using filename of a file within

PostPosted: Fri Mar 03, 2017 3:02 am
by gbfromsd
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?

Thanks,
G

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

PostPosted: Mon Mar 06, 2017 5:48 pm
by therube
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.)

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

PostPosted: Mon Mar 06, 2017 7:25 pm
by therube
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...)

2:Name
Remove
10:Numbering
Prefix ; Start 1 ; Incr 1 ; Pad 5

That should give you files named:

00001.ZIP
...
40000.ZIP

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:)

X\00001
Lumpy Gravy.mp3
Lumpy Gravy.txt
...
X\40000
Simple Man.mp3
Simple Man.txt
Extract all the ZIP into same named directories

DIR /B > DIRS

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

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

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

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

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

TAB:
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.zip" "%X\"

Lumpy Gravy.zip
...
Simple Man.zip

---

Heh, something like that might work.
There's probably an easier way ;-).
http://www.7-zip.org/https://sourceforge.net/projects/gnuwin32/files/coreutils/ (paste.exe & ls.exe, among others)https://sourceforge.net/projects/gnuwin32/files/grep/https://sourceforge.net/projects/gnuwin32/files/sed/