![]() ![]() |
Aug 7 2008, 12:43 AM
Post
#1
|
|
|
Group: Members Posts: 8 Joined: 7-August 08 Member No.: 204322 OS: XP Pro x86
|
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 |
|
|
|
Aug 7 2008, 02:55 AM
Post
#2
|
|
|
Coffee Aficionado ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2568 Joined: 14-July 04 From: Coffeehouse Member No.: 24596 OS: Vista Ultimate x86
|
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)
|
|
|
|
Aug 7 2008, 03:27 AM
Post
#3
|
|
|
Group: Members Posts: 8 Joined: 7-August 08 Member No.: 204322 OS: XP Pro x86
|
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 |
|
|
|
Aug 7 2008, 03:54 AM
Post
#4
|
|
|
Coffee Aficionado ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2568 Joined: 14-July 04 From: Coffeehouse Member No.: 24596 OS: Vista Ultimate x86
|
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. |
|
|
|
Aug 7 2008, 04:10 AM
Post
#5
|
|
|
MSFN Master Group: Software Developers Posts: 2985 Joined: 23-July 04 From: Italy Member No.: 25215 OS: none
|
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 |
|
|
|
Aug 7 2008, 05:09 AM
Post
#6
|
|
|
Group: Members Posts: 8 Joined: 7-August 08 Member No.: 204322 OS: XP Pro x86
|
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 This post has been edited by Brian Jester: Aug 7 2008, 05:12 AM |
|
|
|
Aug 7 2008, 05:49 AM
Post
#7
|
|
|
Coffee Aficionado ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 2568 Joined: 14-July 04 From: Coffeehouse Member No.: 24596 OS: Vista Ultimate x86
|
Does that particular text file have a specific file name? Or does it change from one zip file from another?
|
|
|
|
Aug 7 2008, 06:02 AM
Post
#8
|
|
|
Group: Members Posts: 8 Joined: 7-August 08 Member No.: 204322 OS: XP Pro x86
|
|
|
|
|
Aug 7 2008, 07:35 AM
Post
#9
|
|
|
MSFN Master Group: Software Developers Posts: 2985 Joined: 23-July 04 From: Italy Member No.: 25215 OS: none
|
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
Attached File(s)
|
|
|
|
Aug 7 2008, 08:58 AM
Post
#10
|
|
|
Group: Members Posts: 8 Joined: 7-August 08 Member No.: 204322 OS: XP Pro x86
|
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 This post has been edited by Brian Jester: Aug 7 2008, 09:05 AM |
|
|
|
Aug 7 2008, 10:20 AM
Post
#11
|
|
|
MSFN Master Group: Software Developers Posts: 2985 Joined: 23-July 04 From: Italy Member No.: 25215 OS: none
|
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 ..... Acronyms can be ugly. jaclaz This post has been edited by jaclaz: Aug 7 2008, 10:21 AM |
|
|
|
Aug 7 2008, 05:48 PM
Post
#12
|
|
|
Group: Members Posts: 8 Joined: 7-August 08 Member No.: 204322 OS: XP Pro x86
|
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 ..... 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: 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 This post has been edited by Brian Jester: Aug 7 2008, 05:51 PM |
|
|
|
Aug 8 2008, 02:23 AM
Post
#13
|
|
|
MSFN Master Group: Software Developers Posts: 2985 Joined: 23-July 04 From: Italy Member No.: 25215 OS: none
|
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: 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.... jaclaz
Attached File(s)
|
|
|
|
![]() ![]() |
| Lo-Fi Version | Time is now: 8th September 2008 - 02:29 AM |