Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have about 200+ shareware files in zip format that each contain a file called "FILE_ID.DIZ". I need to know how to rename each instance to lowercase "file_id.diz" without doing it manually - I've already gone that route and it's pretty time consuming. That file has to be lowercase because the BBS program I'm using ignores the FILE_ID.DIZ as a description since it is uppercase. If I manually change it to lowercase, the description is imported successfully.

I know that rar has a renaming switch, but then I'd have to batch convert all of the zip files to rar, and then back to zip. I'm not ruling that out entirely, but it seems like the long way around to resolving this.

I found the man page for "zip_rename", which looks like it might do the trick, but I have no idea how to actually implement it.

I refuse to do this on a Windows machine - I just can't and won't do it... it's the principle ;).

Anyway, thanks for your time!

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

This technique won't rename the file, but add a lowercase version of the .DIZ file. Hopefully it will be good enough for your purposes.

This takes advantage of zip's "add by default" functionality, in which if you specify an existing zip file, it will add files to it. So if you do:

zip doom.zip file_id.diz

and doom.zip exists, it will just add the file_id.diz file to the existing contents.

This is to be run in the directory where your zip files reside:

for i in  *zip; do rm FILE_ID.DIZ;  unzip "$i" FILE_ID.DIZ; mv FILE_ID.DIZ file_id.diz; zip -d "$i" FILE_ID.DIZ; zip "$i" file_id.diz; done

Note that for best results, none of the .zip file names should contain spaces.

You can also put this in a file, say, rename.sh (and it looks nicer and easier to understand this way):

#!/bin/bash
for i in  *zip; do
   rm FILE_ID.DIZ
   unzip "$i" FILE_ID.DIZ
   mv FILE_ID.DIZ file_id.diz
   zip -d "$i" FILE_ID.DIZ
   zip "$i" file_id.diz
done

then you can run by saying, e.g. bash rename.sh

share|improve this answer
    
Thanks! That worked perfectly. This is a great starting point for me. I'm going to see if I can figure out how to write a script to extract each archive to a temp folder, copy the FILE_ID.DIZ to file_id.diz, delete the FILE_ID.DIZ , re-zip the file and then empty the temp directory. –  user73469 Jun 27 '12 at 12:48
    
You can delete files from a zipfile directly with zip -d. I've updated the script to make use of this feature. I suggest you back up your original zip files, whenever we delete stuff it's a good safety net to have :) –  roadmr Jun 27 '12 at 13:58
    
That's fantastic! One thing I noticed is that the script puts a copy of "file_id.diz" in the working directory and also creates a file called "runzip.zip" - I called the script "runzip" for lack of creativity. I just added "rm runzip.zip" and "rm file_id.diz" and it took care of it. –  user73469 Jun 28 '12 at 16:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.