2

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!

2 Answers 2

2

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

3
  • 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, 2012 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, 2012 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, 2012 at 16:10
0

You can use the rename function of zipnote of info-zip: http://www.info-zip.org/FAQ.html#rename

for zip_filename in *.zip; do
    # Only process original zip files.
    if [ "${zip_filename%.fixed.zip}" = "${zip_filename}" ] ; then
        # Create a copy which will be modified later.
        cp ${zip_filename} ${zip_filename%.zip}.fixed.zip

        # Get all filenames, change some of them on the fly and write them to the zip file.
        zipnote ${zip_filename} \
          | sed -e 's/^@ \(.*\)FILE_ID.DIZ/@ \1FILE_ID.DIZ\n@=\1file_id.diz/' \
          | zipnote -w ${zip_filename%.zip}.fixed.zip
    fi
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .