IPB

Google Frontpage Forums Unattended CD/DVD Guide
 
Reply to this topicStart new topic
> Batch Renaming Zip Files, Text Files Inside Zip Archives as the source...
Brian Jester
post Aug 7 2008, 12:43 AM
Post #1





Group: Members
Posts: 8
Joined: 7-August 08
Member No.: 204322
OS: XP Pro x86
Country Flag


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
Go to the top of the page
 
+Quote Post
crahak
post 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
Country Flag


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)
Go to the top of the page
 
+Quote Post
Brian Jester
post Aug 7 2008, 03:27 AM
Post #3





Group: Members
Posts: 8
Joined: 7-August 08
Member No.: 204322
OS: XP Pro x86
Country Flag


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
Go to the top of the page
 
+Quote Post
crahak
post 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
Country Flag


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.
Go to the top of the page
 
+Quote Post
jaclaz
post Aug 7 2008, 04:10 AM
Post #5


MSFN Master
Group Icon

Group: Software Developers
Posts: 2985
Joined: 23-July 04
From: Italy
Member No.: 25215
OS: none
Country Flag


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
Go to the top of the page
 
+Quote Post
Brian Jester
post Aug 7 2008, 05:09 AM
Post #6





Group: Members
Posts: 8
Joined: 7-August 08
Member No.: 204322
OS: XP Pro x86
Country Flag


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

This post has been edited by Brian Jester: Aug 7 2008, 05:12 AM
Go to the top of the page
 
+Quote Post
crahak
post 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
Country Flag


Does that particular text file have a specific file name? Or does it change from one zip file from another?
Go to the top of the page
 
+Quote Post
Brian Jester
post Aug 7 2008, 06:02 AM
Post #8





Group: Members
Posts: 8
Joined: 7-August 08
Member No.: 204322
OS: XP Pro x86
Country Flag


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
Go to the top of the page
 
+Quote Post
jaclaz
post Aug 7 2008, 07:35 AM
Post #9


MSFN Master
Group Icon

Group: Software Developers
Posts: 2985
Joined: 23-July 04
From: Italy
Member No.: 25215
OS: none
Country Flag


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
Attached File(s)
Attached File  renzips.zip ( 990bytes ) Number of downloads: 4
 
Go to the top of the page
 
+Quote Post
Brian Jester
post Aug 7 2008, 08:58 AM
Post #10





Group: Members
Posts: 8
Joined: 7-August 08
Member No.: 204322
OS: XP Pro x86
Country Flag


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

This post has been edited by Brian Jester: Aug 7 2008, 09:05 AM
Go to the top of the page
 
+Quote Post
jaclaz
post Aug 7 2008, 10:20 AM
Post #11


MSFN Master
Group Icon

Group: Software Developers
Posts: 2985
Joined: 23-July 04
From: Italy
Member No.: 25215
OS: none
Country Flag


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

This post has been edited by jaclaz: Aug 7 2008, 10:21 AM
Go to the top of the page
 
+Quote Post
Brian Jester
post Aug 7 2008, 05:48 PM
Post #12





Group: Members
Posts: 8
Joined: 7-August 08
Member No.: 204322
OS: XP Pro x86
Country Flag


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


This post has been edited by Brian Jester: Aug 7 2008, 05:51 PM
Go to the top of the page
 
+Quote Post
jaclaz
post Aug 8 2008, 02:23 AM
Post #13


MSFN Master
Group Icon

Group: Software Developers
Posts: 2985
Joined: 23-July 04
From: Italy
Member No.: 25215
OS: none
Country Flag


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



Attached File(s)
Attached File  renzips1.zip ( 1.17K ) Number of downloads: 6
 
Go to the top of the page
 
+Quote Post

Google Frontpage Forums Unattended CD/DVD Guide

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 8th September 2008 - 02:29 AM
All trademarks mentioned on this page are the property of their respective owners
MSFN is not affiliated with Microsoft
Copyright © 2001-2008 msfn.org
Privacy Policy