Brian Jester Posted August 7, 2008 Posted August 7, 2008 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 descriptionFilename will then be renamed to: hiad.zipThank you!-Brian
CoffeeFiend Posted August 7, 2008 Posted August 7, 2008 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 Posted August 7, 2008 Author Posted August 7, 2008 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
CoffeeFiend Posted August 7, 2008 Posted August 7, 2008 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.
jaclaz Posted August 7, 2008 Posted August 7, 2008 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 Posted August 7, 2008 Author Posted August 7, 2008 (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?jaclazWithout 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 August 7, 2008 by Brian Jester
CoffeeFiend Posted August 7, 2008 Posted August 7, 2008 Does that particular text file have a specific file name? Or does it change from one zip file from another?
Brian Jester Posted August 7, 2008 Author Posted August 7, 2008 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. *.txtThanks!-Brian
jaclaz Posted August 7, 2008 Posted August 7, 2008 Ok, get infozip unzip here:http://www.info-zip.org/UnZip.htmlftp://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. jaclazrenzips.zip
Brian Jester Posted August 7, 2008 Author Posted August 7, 2008 (edited) Ok, get infozip unzip here:http://www.info-zip.org/UnZip.htmlftp://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. jaclazClose, but I want the filename to be 8 characters, and I have files with ~ in the name, I need those removed tooNot 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 August 7, 2008 by Brian Jester
jaclaz Posted August 7, 2008 Posted August 7, 2008 (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%%HI wonder what happens if the text files contains a sentence like:Fantastic unearthly chimes keep all listeners languishing ..... Acronyms can be ugly. jaclaz Edited August 7, 2008 by jaclaz
Brian Jester Posted August 7, 2008 Author Posted August 7, 2008 (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%%HI wonder what happens if the text files contains a sentence like:Fantastic unearthly chimes keep all listeners languishing ..... Acronyms can be ugly. Lol...I will have yet to find out When I change that code, this is the result on renaming the default zip files you sent me:brianjester1.zip renames to: shortfir.zipIn case you don't have those descriptions, here's the description in that file:short first wordjaclaz Edited August 7, 2008 by Brian Jester
jaclaz Posted August 8, 2008 Posted August 8, 2008 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. You said you are not expert enough to code it from scratch, I gave you a base. 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....jaclazrenzips1.zip
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now