This is a bash script to rename snaps (screenshots/previews) to the corresponding ROM file. it easier than tediously doing it manually.
Be warned! It may be buggy. I basically got it to the state where it would read the snaps and the ROMs. You can go back/forward in the ROM list, and skip back/forward by 10 in the snaps list. It displays one ROM and 10 snaps, you choose from the list which one to rename by typing a number from 1 to 10.
I'd strongly suggest running this against a copy of your snaps directory, and only copying it over once you verify the images are correct.
#!/bin/bash
#rename the file, then increment the lists?
#Neo Geo
Filename_Array=(/Roms/NeoGeo/roms/*)
RenamingThese_Array=(/Roms/NeoGeo/snaps/*)
##variables
#counters
Filename_Start=0
Rename_Start=0
skip_amount=10
array_end=$[${#RenamingThese_Array[@]} -$skip_amount]
function rename_files(){
echo
echo ----Original Rom File ----
echo ${Filename_Array[Filename_Start]}
echo
IFS="^"
a=$Rename_Start
b=$[Rename_Start+1]
c=$[Rename_Start+2]
d=$[Rename_Start+3]
e=$[Rename_Start+4]
f=$[Rename_Start+5]
g=$[Rename_Start+6]
h=$[Rename_Start+7]
i=$[Rename_Start+8]
j=$[Rename_Start+9]
names=(
${RenamingThese_Array[a]}
${RenamingThese_Array[b]}
${RenamingThese_Array[c]}
${RenamingThese_Array[d]}
${RenamingThese_Array[e]}
${RenamingThese_Array[f]}
${RenamingThese_Array[g]}
${RenamingThese_Array[h]}
${RenamingThese_Array[i]}
${RenamingThese_Array[j]}
next5 back5 previous_rom skip_5_roms)
echo ----Rename File ----
echo Press any other key to skip renaming the image file
PS3="Choose an image file (1-$skip_amount) to rename:"
select varname in ${names[*]}; do
if [[ -n "$varname" ]]; then
# chop off the filename from $varname, and from ${Filename_Array[0]}
echo ${Filename_Array[Filename_Start]}
echo $varname
if [[ $varname = "next5" ]]; then
Rename_Start=$[$Rename_Start+$skip_amount]
if [[ $Rename_Start -gt $array_end ]]; then
echo $array_end
echo $Rename_Start
echo "Reached the end of the list of images"
Rename_Start=$array_end
fi
break
fi
if [[ $varname = "back5" ]]; then
Rename_Start=$[$Rename_Start-$skip_amount]
if [[ $Rename_Start -lt 0 ]]; then
echo "Reached the start of the list of images"
Rename_Start=0
fi
break
fi
if [[ $varname = "previous_rom" ]]; then
Filename_Start=$[$Filename_Start-1]
if [[ $Filename_Start -lt 0 ]]; then
echo "Reached the start of the list of images"
Filename_Start=0
fi
break
fi
if [[ $varname = "skip_5_roms" ]]; then
Filename_Start=$[$Filename_Start+1]
break
fi
# get only the file name of the file
FILENAME_AND_EXTN=$(echo ${Filename_Array[Filename_Start]} | rev | cut -d"/" -f1 | rev)
FILENAME=$( echo $FILENAME_AND_EXTN | cut -d"." -f1)
VARNAME_AND_EXTN=$(echo $varname | rev | cut -d"/" -f1 | rev)
EXTENSION=$( echo $varname | cut -d"." -f2)
#EXTENSION=jpg
# get the path of the destination directory
ONLY_PATH=$(echo $varname | rev | cut -d"/" -f2- | rev)
echo mv "$varname" "$ONLY_PATH/$FILENAME.$EXTENSION"
mv "$varname" "$ONLY_PATH/$FILENAME.$EXTENSION"
#increment files to process
Filename_Start=$[$Filename_Start+1]
#Rename_Start=$[$Rename_Start+1]
# start over
#function rename
break
else
echo 'skipped renaming file'
echo $Rename_Start
Filename_Start=$[$Filename_Start+1]
break
fi
done
#echo $Filename_Start
rename_files
}
rename_files
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment