09 September 2012

Converting archives

How To Batch Convert Files From ACE Compression to ZIP

So recently I realized I had a bunch of ACE compressed files that I couldn't open in a lot of other computers without having to install additional software. That over time was becoming less and less ideal so in the end I gave up and decided to recompress all these files to something a little more generic, like .zip

As background history, I must say the reason I had so many .ace files was because a few years ago (after some intensive testing) I determined that the ACE format was giving me the best compression results. Props go to WinACE for consistently beating all other windows based compression algorithms I could get my hands on at the time. I don't know if that is still true as the 7zip and a few others have progressed by leaps and bounds since then, but it seems like winace is still a decent choice as far as file size is concerned.
Unfortunately, it seems like the format never got a huge public support and didn't spread to become ubiquitous enough to be easy to use and share files with. Thus, my decision to recompress files into something more accessible.

After I started converting a few files, I decided it was taking too long to do them all one by one, so I wrote the following script to get a directory full with *.ace files and recompress them all one by one to their .zip equivalents.


#!/bin/bash
mkdir tmp
for i in *.ace
do
        echo "Recompressing $i"
        mv "$i" "tmp/$i"
        cd tmp
        unace x "$i"
        rm "$i"
        zip -mr "$i.zip" *
        mv "$i.zip" ../
        cd ..
        echo "Done $i"
done
rm -r tmp



Rehash of what it is doing.

  1. Create a temporary directory
  2. For each file with .ace extension, do the following
  3. Move the .ace file to the temporary directory
  4. Extract the files
  5. Delete the .ace file
  6. Compress the files to .zip (and delete them)
  7. Move the ready .zip file to the original directory
  8. Continue with the next .ace file
  9. When done, delete the temporary directory.
Please note that with a small change to this script, this can be modified to batch change files from any supported format to any other supported format (change the unace and zip lines with their equivalents).

Also note, I'm using the unace program, which typically does not come pre-installed with distributions, but most distros would have it in their repositories.

No comments: