Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Argument to script should be a filename with a list of mame romnames without file ending.
- # It takes a base directory with MAME EXTRAs files and searches in pre defined comma separated
- # directories like flyers,snap for .png files. These .png files must match the list of romnames
- # found in the file from argument. The list of romnames in file must be new line separated without
- # file extension. It only copies the first found image and leaves out the rest.
- # Argument 1 is a file with romnames without file ending separated by new line. In example:
- # bosco
- # bjourney
- # lizwiz
- filename="$1"
- # This is the base directory to look for files to copy. It is assumened that this directory have
- # subfolders with those images. Usually it is the mame base folder, where all these EXTRAs subfolders
- # are found.
- basedir="/media/tuncay/K/roms/Pleasuredome/mame/MAME 0.155 EXTRAs"
- # List of directories to use found in base directory. The list should be comma separated.
- includedir="flyers,marquees,snap"
- # Error messages sent to this file. Contains only an entry for each romname, if nothing is found.
- logfile="log_single.txt"
- # Remove previous logfile.
- rm "$logfile"
- # Create folder to copy files to.
- mkdir -p "extras"
- # counter is just temporary number for the print for each romname.
- counter=0
- # Use the file from argument as the input. Each line represents a romname.
- for line in $(cat "$filename")
- do
- # Proceed only if the line is not empty.
- if [ -z "$line" ];
- then
- continue
- else
- # Print the actual romname in line of file and corresponding number.
- counter=$[$counter+1]
- romname="$line"
- echo "$counter - $romname"
- # Look for each directory in the comma separated list to copy files from.
- # Variable found will be set to true, if any file for a romname is found.
- found=false
- for dir in $(echo $includedir | sed "s/,/ /g")
- do
- # Build up final file to look at. If file exists, then copy it into
- # the created folder. If not, write a line that the file does not exist.
- # Look only for first found file and then exit for searching next romname.
- file="$basedir/$dir/$romname.png"
- if [ -f "$file" ];
- then
- cp "$file" "extras/$romname-$dir.png"
- found=true
- break
- else
- found=false
- fi
- done
- # If nothing is found per romname, it will create a only one entry for each romname.
- if [ "$found" = false ];
- then
- echo "Nothing found for $romname." >> "$logfile"
- fi
- fi # End of Proceed only if the line is not empty.
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement