RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Convert batch file to a linux script

    Scheduled Pinned Locked Moved Help and Support
    scripting
    3 Posts 2 Posters 1.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • iCLintI
      iCLint
      last edited by

      Edit: sorry, this should probably be in "help and support" but for some strange reason I get an error "category doesn't exist when trying to submit.

      Hi, I found this Batch file in the forums (Sorry for not crediting the creator as I can't remember where I found it now).

      The batch file scans a directory of ROMS which looks for a directory called "images" for a png with the same name as the ROM and it creates an XML file for ES.

      It isn't perfect though.

      1. I found I had to do a few Find and replace's with a good text editor to clean up the XML (easily fixed though I just haven't bothered to yet.) the path to the images doesn't work i have to replace "~/retropie/roms/arcade//images" to "./images"
      2. it runs from windows and scans the drive share which makes it very slow.
      3. I use OS X so I have to boot back and forth from windows to use the script
      4. for MAME ROMS I remove the ROM name from the <name></name > tag as ES scrapes the ROMS and puts in the full game name rather than just the shortened file name.

      you might ask me why I don't use one of the built scrappers? personally I haven't had much luck with any of them (ES and Sselph). most the time it renames the coms incorrectly adds the wrong image or doesn't find a match at all

      My process which has been working perfectly is, collect my set of ROMS, use Hypersync from the Hyperspin project to scan and download all the needed images, place said images into the "images folder", run the batch file and presto all my ROMS with images in a ES compatible XML.

      The script is extremely simple. I was hoping someone could help me convert it into a script that could be run directly from the RPi CLI?

      If run from the RPi it would be near instant even on the largest of rom collections

      @echo off
      echo Working...
      echo ^<?xml version="1.0"?^> > gamelist.xml
      echo ^<gameList^> >> gamelist.xml
      for /f "delims=" %%a in ('dir /b') do cls && echo Working... && echo %%~na && echo ^<game^> >> gamelist.xml && echo ^<path^>.^/%%a^</path^> >> gamelist.xml && echo ^<name^>%%~na^</name^> >> gamelist.xml && echo ^<desc^>^<^/desc^> >> gamelist.xml && echo ^<image^>^~^/RetroPie^/roms^/%1^/images^/%%~na.png^</image^> >> gamelist.xml && echo ^<rating^>^</rating^> >> gamelist.xml && echo ^<developer^>^</developer^> >> gamelist.xml && echo ^<publisher^>^</publisher^> >> gamelist.xml && echo ^<genre^>^</genre^> >> gamelist.xml && echo ^<players^>^</players^> >> gamelist.xml && echo ^<^/game^> >> gamelist.xml
      echo ^<^/gameList^> >> gamelist.xml
      cls
      echo Done!

      I would do it myself and still will if I don't get any help, but I am only just learning linux and trying to wrap my head around the file system and CLI.

      1 Reply Last reply Reply Quote 0
      • BuZzB
        BuZz administrators
        last edited by BuZz

        Please use formatting if posting configs/code to the forum - https://retropie.org.uk/forum/topic/3/read-this-first - I will format your post.

        [edit] I can't format it as it's full of whitespace - you may want to edit / repaste it correctly into a code block otherwise content from it could be lost / not displayed correctly

        To help us help you - please make sure you read the sticky topics before posting - https://retropie.org.uk/forum/topic/3/read-this-first

        1 Reply Last reply Reply Quote 0
        • iCLintI
          iCLint
          last edited by iCLint

          Answering my own question. I will start a new thread with full usage

          #!/bin/bash
          
          # Script use $ sudo ./makexml.sh [RomDirectoryName] [-n optional]
          # -n does not right name to <name> tag useful for MAME roms as ES will autofill correct name
          
          # Store arguments
          arg1=$1
          arg2=$2
          output="gamelist.xml"
          
          # Change deliminator for $IFS 
          # Allows script to work with names with white space
          SAVEIFS=$IFS
          IFS=$(echo -en "\n\b")
          
          # print scripts current status 
          printf "Scanning dir: "$arg1"...\n"
          
          # Creates output XML file (gamelist.xml)
          printf "<?xml version=\"1.0\"?>\n\n" > ./$arg1/$output  
          printf "<gameList>\n" >> ./$arg1/$output
          
          # Scans directory given by first argument
          for file in ./$arg1/*
          do
                  # Just some manipulatiuon of data returned by $file 
                  filename=$(echo $file | cut -f 3 -d '/')
                  name=$(echo $filename | cut -f 1 -d '.')
          
                  # Checking for existance of correctly named image in ./images dir.
                  [[ -f ./$arg1/images/$name.png ]] && theImage=./images/$name.png || theImage=""
          
                  # Start writing to gamelist.xml
                  printf "\n" >> ./$arg1/$output
                  printf "\t<game>\n" >> ./$arg1/$output
                  printf "\t\t<path>./"$filename"</path>\n" >> ./$arg1/$output
          
                  # Checking whether the -n argument was used
                  if [ $arg2 = "-n" ]; then
                  name=""
                  fi
          
                  # Continuing writing to gamelist.xml
                  printf "\t\t<name>"$name"</name>\n" >> ./$arg1/$output
                  printf "\t\t<desc></desc>\n" >> ./$arg1/$output
                  printf "\t\t<image>"$theImage"</image>\n" >> ./$arg1/$output
                  printf "\t\t<rating></rating>\n" >> ./$arg1/$output
                  printf "\t\t<releasedate></releasedate>\n" >> ./$arg1/$output
                  printf "\t\t<developer></developer>\n" >> ./$arg1/$output
                  printf "\t\t<publisher></publisher>\n" >> ./$arg1/$output
                  printf "\t\t<genre></genre>\n" >> ./$arg1/$output
                  printf "\t\t<players></players>\n" >> ./$arg1/$output
                  printf "\t</game>\n" >> ./$arg1/$output
          
                  # Print scripts current status
                  printf $filename
                  clear
                  printf "Scanning dir: "$arg1"...\n"
                  done
          
          # Closing gamelist.xml file
          printf "</gameList>" >> ./$arg1/$output
          
          # print scripts current status
          clear
          printf "Finished\n"
          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

          Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.