Help - Search - Members - Calendar
Full Version: Batch Renaming Zip Files
MSFN Forums > Software, Hardware, Media and Games Central > Software Hangout

   
Google Internet Forums Unattended CD/DVD Guide
Brian Jester
Hi,

Can you tell how I can go about batch renaming Zip archives based on the contents of text files which are already inside the zip files?

Here's an example of what I need done:

File.zip contains a text file and the File.zip will be renamed based on the First character of each word inside the text file...So for example if the text file inside the zip says: Here is a description

Filename will then be renamed to: hiad.zip

Thank you!
-Brian
crahak
I don't think you'll find ready-made apps to do something so unusual & specific. It could be done though (a library would do all the heavy lifting -- unzipping files)
Brian Jester
QUOTE (crahak @ Aug 7 2008, 03:55 AM) *
I don't think you'll find ready-made apps to do something so unusual & specific. It could be done though (a library would do all the heavy lifting -- unzipping files)


Could you show something that * Could * work? If it's something using server side scripting such as php, I could try that, but I am not good enough to code it from scratch...I am looking for something already done. Please post complete *working* scripts.

Thanks!
-Brian
crahak
QUOTE (Brian Jester @ Aug 7 2008, 05:27 AM) *
Could you show something that * Could * work?

Sure. But I'd need more infos first.

QUOTE (Brian Jester @ Aug 7 2008, 05:27 AM) *
If it's something using server side scripting such as php, I could try that, but I am not good enough to code it from scratch...

I do PHP only as a last resort newwink.gif

If you want someone to make an app or script something for you then we need more detail like I said. Things like: that text file inside the zip, that we're supposed to generate the zip filename from, what is it called? And things like what to do when the said text file is quite big, and that the generated filename would have to be like 5000 characters long? I suppose we could also drop all invalid characters...

The idea is to unzip the said textfile, either using a command line util (for scripts) or a suitable library (e.g. SharpZipLib for a C# app), look in some text file (gotta know which one), extract the words (using a regular expression would work fine), generating the new name, renaming the zip file and deleting the temp file (unless it was unzipped to memory)

It's not a 5 minute job, but it's still easy to do, as long as we know precisely what it has to do. The more details, the better.
jaclaz
It is doable in batch, I think.

Can you post a couple of SMALL examples of these .zips?

Is it correct to say that every .zip file contains just one .txt file?

Are you positive that all .txt files inside the .zip files begin with a DIFFERENT word?

jaclaz
Brian Jester
QUOTE (jaclaz @ Aug 7 2008, 05:10 AM) *
It is doable in batch, I think.

Can you post a couple of SMALL examples of these .zips?

Is it correct to say that every .zip file contains just one .txt file?

Are you positive that all .txt files inside the .zip files begin with a DIFFERENT word?

jaclaz


Without having to post files, I will say that the zip files contain 2 files inside, one is a sound file, and another is a text file containing the long filename, so basically what I want to do is use that long to extract a dos > 8.3 compatible filename name from it, and apply it to the zip file. Every description inside the text file is no more than 8 DIFFERENT words. I already know that.

Thanks for the help!
-Brian
crahak
Does that particular text file have a specific file name? Or does it change from one zip file from another?
Brian Jester
QUOTE (crahak @ Aug 7 2008, 06:49 AM) *
Does that particular text file have a specific file name? Or does it change from one zip file from another?


They are different, but they are all txt extensions, so I guess a wildcard trick should do. *.txt

Thanks!
-Brian
jaclaz
Ok, get infozip unzip here:
http://www.info-zip.org/UnZip.html
ftp://tug.ctan.org/tex-archive/tools/zip/info-zip/WIN32/
ftp://tug.ctan.org/tex-archive/tools/zip/...32/unz552xN.exe
(you need just the file unzip.exe from inside the sfx unz551xN.exe)

Put unzip.exe and the attached renzips.cmd in the same folder where your .zips are and run renzips.cmd.

First test it with the eclosed brianjester1.zip and brianjester2.zip.

The .cmd is just an example, feel free to modify as you wish. newwink.gif

jaclaz
Brian Jester
QUOTE (jaclaz @ Aug 7 2008, 08:35 AM) *
Ok, get infozip unzip here:
http://www.info-zip.org/UnZip.html
ftp://tug.ctan.org/tex-archive/tools/zip/info-zip/WIN32/
ftp://tug.ctan.org/tex-archive/tools/zip/...32/unz552xN.exe
(you need just the file unzip.exe from inside the sfx unz551xN.exe)

Put unzip.exe and the attached renzips.cmd in the same folder where your .zips are and run renzips.cmd.

First test it with the eclosed brianjester1.zip and brianjester2.zip.

The .cmd is just an example, feel free to modify as you wish. newwink.gif

jaclaz



Close, but I want the filename to be 8 characters, and I have files with ~ in the name, I need those removed too

Not the first word, but the first letter of each word...Like I said, the txt file has NO MORE THAN 8 words.

Thank you for the help!
-Brian
jaclaz
Well, as said that was just a quick example.

Change the parsing in the second FOR /F loop to something like:
CODE
IF %found%==1 FOR /F "tokens=1,2,3,4,5,6,7,8 delims= " %%A IN ('UNZIP -p %targetzip% %name%%ext%') DO SET firstword=%%A%%B%%C%%D%%E%%F%%G%%H


I wonder what happens if the text files contains a sentence like:
QUOTE
Fantastic unearthly chimes keep all listeners languishing .....

woot.gif
Acronyms can be ugly. angel.gif

jaclaz
Brian Jester
QUOTE (jaclaz @ Aug 7 2008, 11:20 AM) *
Well, as said that was just a quick example.

Change the parsing in the second FOR /F loop to something like:
CODE
IF %found%==1 FOR /F "tokens=1,2,3,4,5,6,7,8 delims= " %%A IN ('UNZIP -p %targetzip% %name%%ext%') DO SET firstword=%%A%%B%%C%%D%%E%%F%%G%%H


I wonder what happens if the text files contains a sentence like:
QUOTE
Fantastic unearthly chimes keep all listeners languishing .....

woot.gif
Acronyms can be ugly. angel.gif

Lol...I will have yet to find out thumbup.gif

When I change that code, this is the result on renaming the default zip files you sent me:

CODE
brianjester1.zip renames to: shortfir.zip


In case you don't have those descriptions, here's the description in that file:

CODE
short first word


jaclaz
jaclaz
Sure, the idea behind a forum thread is not that of a "rent-a-coder-for-free", you should put something of yours in the batch. mad.gif

You said you are not expert enough to code it from scratch, I gave you a base. whistling.gif

If you just try to understand how it works, you will see that just a few lines below the FOR /F loop there is a line:
QUOTE
Set firstword=%firstword:~0,8%

that limits the length to 8 characters, using a similar syntax will get the first letter of each word, once put in a loop.

However, since I am really a nice guy, try the attached files....newwink.gif

jaclaz


Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.