Advertisement
Guest User

getextras_all.sh

a guest
Aug 20th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.44 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Argument to script should be a filename with a list of mame romnames without file ending.
  4. # It takes a base directory with MAME EXTRAs files and searches in pre defined comma separated
  5. # directories like flyers,snap for .png files. These .png files must match the list of romnames
  6. # found in the file from argument. The list of romnames in file must be new line separated without
  7. # file extension. The script will create the corresponding directories and copy all matching files
  8. # to there places.
  9.  
  10. # Argument 1 is a file with romnames without file ending separated by new line. In example:
  11. # bosco
  12. # bjourney
  13. # lizwiz
  14. filename="$1"
  15.  
  16. # This is the base directory to look for files to copy. It is assumened that this directory have
  17. # subfolders with those images. Usually it is the mame base folder, where all these EXTRAs subfolders
  18. # are found.
  19. basedir="/media/tuncay/K/roms/Pleasuredome/mame/MAME 0.155 EXTRAs"
  20.  
  21. # List of directories to use found in base directory. The list should be comma separated.
  22. includedir="flyers,marquees,snap"
  23.  
  24. # Error messages sent to this file. Contains an entry for each not found image with full path.
  25. logfile="log_all.txt"
  26.  
  27. # Remove previous logfile.
  28. rm "$logfile"
  29.  
  30. # Create all folders to copy files from.
  31. for dir in $(echo $includedir | sed "s/,/ /g")
  32. do
  33.     mkdir -p "$dir"
  34. done
  35.  
  36. # counter is just temporary number for the print for each romname.
  37. counter=0
  38. # Use the file from argument as the input. Each line represents a romname.
  39. for line in $(cat "$filename")
  40. do
  41.     # Proceed only if the line is not empty.
  42.     if [ -z "$line" ];
  43.     then
  44.         continue
  45.     else
  46.         # Print the actual romname in line of file and corresponding number.
  47.         counter=$[$counter+1]
  48.         romname="$line"
  49.         echo "$counter - $romname"
  50.        
  51.         # Look for each directory in the comma separated list to copy files from.
  52.         for dir in $(echo $includedir | sed "s/,/ /g")
  53.         do
  54.             # Build up final file to look at. If file exists, then copy it into
  55.             # the created folder. If not, write a line that the file does not exist.
  56.             file="$basedir/$dir/$romname.png"
  57.             if [ -f "$file" ];
  58.             then
  59.                cp "$file" "$dir/$romname.png"
  60.             else
  61.                echo "File $file does not exist." >> "$logfile"
  62.             fi
  63.         done
  64.        
  65.     fi # End of Proceed only if the line is not empty.
  66. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement