Hello everybody,
I am new in the forum and a recent owner of an Everdrive N64 v3.0.
As a new guest I came with a present and I would like to share you a small script for Linux users that sorts the games into folders.
But please be easy with these lines code that I wrote even if I AM NOT A PROGRAMMER!!! I am only a copy-paste user.
So use it carefully and feel free to share critics!
Main process:
* Select a folder
* Search for ROMS, that is to say files having the following extensions in this folder but not in the subfolders:
".bin" ; ".jap" ; ".n64" ; ".N64" ; ".pal" ; ".rom" ; ".u64" ; ".v64" ; ".usa" ; ".z64" ; ".d64"
* Move all ROMS found in folders named A to Z. But all ROMS that have names starting with a number are placed in one folder named "0-9"
Exit functions:
* By the user while choosing the folder to parse
* If no ROM found
#!/bin/bash
## Disclaimer
zenity --info --title='ROMS folder creator' --width=300 --height=100 --text="\nSCRIPT TO SORT ROMS IN SEVERAL FOLDERS.\n\nThis script creates folders named 0-9 or A to Z and moves the games into them.\nClic to choose the folder to be parsed and modified.\n\nTHE MODIFICATIONS CANNOT BE UNDONE!!! But the script can be stopped at the next step."
## Choose folder; Exit if cancel
folder=$(zenity --file-selection --directory --title=' Choose folder to clean or exit')
if [ $? = 1 ]; then
zenity --info --title='End of script' --width=300 --height=100 --text="\nSCRIPT CANCELED.\n\nNothing modified.\nClic to close the window and stop the script."
exit
fi
## Change the current working directory
cd "$folder"
## Parse folder to list *.n64 files; Exit if no file found
list_of_roms=$(ls | grep -e ".bin" -e ".jap" -e ".n64" -e ".N64" -e ".pal" -e ".rom" -e ".u64" -e ".v64" -e ".usa" -e ".z64" -e ".d64")
if [ -z "$list_of_roms" ]; then
zenity --info --title='End of script' --width=150 --height=100 --text="\nNO ROM FOUND.\n\nNothing modified.\nClic to close the window and stop the script."
exit
fi
## Count of files found
nb_files=$((echo -e "$list_of_roms" | wc -l) | cut -d" " -f1)
## Prompt continue
zenity --question --title='Research done' --width=200 --height=150 --text="\n$nb_files ROM(S) FOUND.\n\nNothing modified yet.\nDo you want to move them into subfolders?"
if [ $? = 1 ]; then
zenity --info --title='End of script' --width=300 --height=100 --text="\nSCRIPT CANCELED.\n\nNothing modified.\nClic to close the window and stop the script."
exit
fi
## Loop i on nb_files, creates folders if not existing and move roms into them
(echo "0" ; sleep 1
for ((i=1;i<=$nb_files;i++))
do
echo "# File $i / $nb_files" ; sleep 0
rom_i=$(echo "$list_of_roms" | sed -n "$i p")
folder_i=$(echo "${rom_i:0:1}" | tr '[:lower:]' '[:upper:]')
if [ "$folder_i" -eq "$folder_i" ] 2>/dev/null; then
folder_i="0-9"
else
folder_i=$folder_i
fi
[ -d $folder_i ] || mkdir $folder_i
mv "$rom_i" $folder_i
percentage=`expr $i \* 100 / $nb_files`
percentage_txt=$(echo "$percentage")
echo "$percentage" ; sleep 0
done
echo -e "# WORK DONE. $nb_files ROM(S) moved." ; sleep 0.5) |
zenity --progress \
--title="Moving files" \
--text="Start..." \
--auto-close \
--percentage=0 \
--width=150 \
--height=150
## End of script
if [ $? = 1 ]; then
list_of_roms_end=$(ls | grep -e ".bin" -e ".jap" -e ".n64" -e ".N64" -e ".pal" -e ".rom" -e ".u64" -e ".v64" -e ".usa" -e ".z64" -e ".d64")
nb_files_end=$((echo -e "$list_of_roms_end" | wc -l) | cut -d" " -f1)
nb_files_moved=$(($nb_files-$nb_files_end))
zenity --info --title='End of script' --width=300 --height=100 --text="\nSCRIPT CANCELED.\n\n$nb_files_moved/$nb_files ROM(S) moved.\nClic to close the window and stop the script."
exit
fi
zenity --info --title='End of script' --width=150 --height=100 --text="\nWORK DONE.\n\n$nb_files ROM(S) moved.\nClic to close the window."
Edit 25/08/2018:
* Added all extensions searched (initially only ".n64")
See
https://en.wikipedia.org/wiki/List_of_Nintendo_64_ROM_file_formats* Correction of the "folder" variable, it was not compatible with "space"
Edit#2 25/08/2018:
* Added a prompt with info before moving any file
* Added a progress bar while moving files, it gives the possibility to stop the work during the loop