Macos – How to bulk rename files in a RAR or ZIP archive on the mac

archivingmacosrarrenamezip

I have a set of archive files — both zip and rar formats — inside of which I need to rename some files. Specifically, I want to do something like this:

for each archive file in a directory
    for each file in the archive
        if the file name matches the regular expression /(.* - [0-9]{2})([0-9]{2} - .)*/
            rename the file as \1-\2

The trick isn't so much in the generation of the new name; I can do that with either bash or sed or anything else. It's the set of commands to manipulate the files in the archives using rar/unrar or unzip/zip

(If it makes a difference, I'm re-formatting some CBR/CBZ files to get the double-page spreads to come up in the right order in SimpleComic — it interprets page 0203 as page 203, which makes the story a bit hard to follow)

Best Answer

I think the easiest way you'll find to do this is to unpack each archive, do the rename operation, then repack it.

On Linux, I could use a FUSE filesystem to have transparently decompressed archives, which I could operate on like regular folders, using a batch script to do all the renaming. I don't know if that particular FUSE filesystem exists for Mac.

Related Question