I have a bunch of .zip and .rar files. Many of these files contain subfolders in the archive. I want to remove all the folders from the zip files but keep the other content.
e.g.
original.zip
- /foo/bar1.jpg
- /foo/bar2.jpg
- /foo/bar3.jpg
- /foo/bar4.jpg
>>>
new.zip
- bar1.jpg
- bar2.jpg
- bar3.jpg
- bar4.jpg
This can be a pure terminal command or a bash script. I need to be able to run it on 100s of zip/rar files at once.
update: This doesn't seem to be possible w/o recreating the zips + rars.
So I have written a little bash script, it creates two dirs, "cleaned" for post-processed files, and "temp" for the unzipped files. It loops through all archives in the current directory (.cbr and .cbz files), it creates a "clean name" for each new file, unzips the old file to the temp dir, creates a new archive from the temp files and saves it with the clean name in the "cleaned" directory, then clears out the temp folder. after all files are processes the "temp" dir is recursively removed. here's what it looks like:
#!/bin/bash
echo "comic cleaning!";
echo "---------------";
dir=$(pwd)/;
tmp=${dir}temp/;
clean=$(pwd)/cleaned;
cd $dir;
mkdir -p cleaned;
mkdir -p temp;
for z in *.cb*; do
cd $dir;
filename=$(basename "$z");
rawname="${filename%.*}";
name="${rawname// /_}";
7z e "$dir$z" -otemp/;
cd $tmp && zip -r $clean/$name.cbz *.jpg;
cd $tmp && rm *.*;
done
cd $dir && rm -rf $tmp;
I should probably be using the os /tmp dir, but I'm still new at bash and couldn't get it to work. Any suggestions to optimizing it?