Jump to content

Recommended Posts

Posted

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


Posted

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)

Posted
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

Posted
Could you show something that * Could * work?

Sure. But I'd need more infos first.

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

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.

Posted

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

Posted (edited)
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

Edited by Brian Jester
Posted
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

Posted

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. ;)

jaclaz

renzips.zip

Posted (edited)
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. ;)

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

Edited by Brian Jester
Posted (edited)

Well, as said that was just a quick example.

Change the parsing in the second FOR /F loop to something like:

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:

Fantastic unearthly chimes keep all listeners languishing .....

:w00t:

Acronyms can be ugly. :angel

jaclaz

Edited by jaclaz
Posted (edited)
Well, as said that was just a quick example.

Change the parsing in the second FOR /F loop to something like:

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:

Fantastic unearthly chimes keep all listeners languishing .....

:w00t:

Acronyms can be ugly. :angel

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

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

brianjester1.zip renames to: shortfir.zip

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

short first word

jaclaz

Edited by Brian Jester
Posted

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. :angry:

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

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:

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....;)

jaclaz

renzips1.zip

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...