In advance,
- install 7-zip in "d:\cext\Program Files\7-Zip".
- install git from https://git-scm.com/download/win
trans_to_7z.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #!/bin/bash PARENTDIR=$1 TMPDIR=`pwd`/tmp PATH="/d/cext/Program Files/7-Zip:$PATH" ISERR="no" if [ "x$1" = x ] ; then echo "Please input dir to transform." exit fi if [ -e "$TMPDIR" ] ; then echo "Please rmdir [$TMPDIR] first." exit fi get_win_path() { local win_path="$1" win_path="${win_path#/}" win_path="${win_path//\//\\}" win_path="${win_path/\\/\:\\}" echo $win_path } format_transform() { local file_7z=$1 local file_zip=$2 local tmp_dir=$TMPDIR mkdir "$tmp_dir" 7z x ${file_7z} -o"`get_win_path \"$tmp_dir\"`" ( cd "$tmp_dir" ls 7z a -mx9 "`get_win_path \"${file_zip}\"`" || ( echo "Creating 7z file failed." && ISERR="yes" ) ) rm -Rf "$tmp_dir" } cd "$PARENTDIR" for fn in `ls *.zip`; do echo "$fn" format_transform $fn "`pwd`/${fn%.zip}.7z" if [ $ISERR = "yes" ]; then exit fi done echo "Transforming done." |
How to use?
Copy trans_to_7z.sh to Mame root folder which contains roms sub-directory, right click at blank place of this Mame root window in Explorer, select "Git Bash Here" which prompts bash console, input below and return,
1 | ./trans_to_7z.sh roms |