Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Need help writing a .bat file  (Read 1444 times)

0 Members and 1 Guest are viewing this topic.

rodneykristy

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 8
  • Last login:April 17, 2017, 10:10:54 pm
  • I want to build my own arcade controls!
Need help writing a .bat file
« on: May 17, 2016, 08:29:15 am »
Ok, so I'm trying to figure out how to write a .bat file to copy only select rom files from a text list to another directory. I haven't wrote a .bat file in years and not sure how to go about this. The rom list is basically my favorite games I have saved in MAMEUIFX which is stored in the favorites.ini file. I really want to just copy that list and insert it into a .bat file so I can run it to copy only my favorite rom files to another drive to cut down on gigabytes of space. I only have about 200 or so games on that list but it's still time consuming to manually copy the roms to another drive. It would be awesome to be able to update my favorites and then recopy them ever so often with any new ones I've added to that list whenever I update my roms. Basically the list looks something like this...

1941u
1942
1943u
1944
19xx
aliensu
altbeast
armwaru
astdelux
asteroid
astorm
atetris
avengrgs
avspu
baddudes
batcir
batman
berserk

I would just paste that into a .bat file and run it to copy only those roms. Hope that makes sense and thanks in advance for info you have regarding this.

haynor666

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1547
  • Last login:Yesterday at 06:19:45 am
  • retro maniac
Re: Need help writing a .bat file
« Reply #1 on: May 17, 2016, 08:44:15 am »
Code: [Select]
for /f "delims=" %%i in ([list].txt) do copy "[source]\%%i.zip" "[destination]"
« Last Edit: May 17, 2016, 05:46:06 pm by haynor666 »

rodneykristy

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 8
  • Last login:April 17, 2017, 10:10:54 pm
  • I want to build my own arcade controls!
Re: Need help writing a .bat file
« Reply #2 on: May 17, 2016, 08:51:06 am »
Can you explain this a little in detail? I'm not sure what all this means. I'm not very good at writing .bat files at all. Thanks

johnrt

  • Guest
  • Trade Count: (0)
Re: Need help writing a .bat file
« Reply #3 on: May 17, 2016, 08:55:38 am »
This is the contents of your file. Copy this text into notepad and save it as copyroms.bat
Quote
@echo off
SET SRCDIR=C:\PATH\TO\SOURCE
SET DSTDIR=C:\PATH\TO\DESTINATION
SET MYLIST=C:\PATH\TO\MYLIST\mylist.txt
FOR /F "tokens=*" %%A in (%MYLIST%) do copy %SRCDIR%\%%A.zip %DSTDIR%

Edit the file to suit your needs. SRCDIR is where your ROMS are located. DSTDIR is the path to where you need the ROMS to be copied. MYLIST is a textfile with the following contents:
Quote
1941u
1942
1943u
1944
19xx
aliensu
altbeast
armwaru
astdelux
asteroid
astorm
atetris
avengrgs
avspu
baddudes
batcir
batman
berserk

johnrt

  • Guest
  • Trade Count: (0)
Re: Need help writing a .bat file
« Reply #4 on: May 17, 2016, 09:37:07 am »
And here's the bat-file if your foldernames contains spaces:

Quote
@echo off
SET "SRCDIR=C:\PATH\TO THE\SOURCE"
SET "DSTDIR=C:\PATH\TO THE\DESTINATION"
SET "MYLIST=C:\PATH\TO THE\MYLIST\mylist.txt"
FOR /F "USEBACKQtokens=*" %%A in ("%MYLIST%") do copy "%SRCDIR%\%%A.zip" "%DSTDIR%"

IMPORTANT! Only edit the lines that starts with SET

yamatetsu

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2725
  • Last login:Today at 03:13:22 pm
  • Just because.
Re: Need help writing a .bat file
« Reply #5 on: May 17, 2016, 10:30:28 am »
You can use an editor that has a macro feature for that. I recommend notepad++, which is free (https://notepad-plus-plus.org/).

Go to your roms folder. Make a new folder named 'favs' (without the ').

Open up notepad++. Open the .txt file that contains the rom names.

Go to the top of your file. Click at the first position to make sure that the cursor is positioned before the first letter of the first romname.

Go to the 'macro' menu, select 'start recording'.

Type 'copy ' (without the '), hit the 'end' key to go to the end of the line.

Type '.zip favs\' (without the '), then hit the 'home' key to go to the beginning of the line. You should now have something like 'copy firstromname.zip favs\'

Hit 'arrow down' to go to the beginning of the next line.

Go to the 'macro' menu, select 'stop recording'.
In the 'macro' menu, select 'run a macro multiple times', then 'run until the end of file'.

Use 'save as' to save the file as 'roms.bat' to your roms folder.

Start roms.bat, it will copy the roms into the favs folder.
                  

haynor666

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1547
  • Last login:Yesterday at 06:19:45 am
  • retro maniac
Re: Need help writing a .bat file
« Reply #6 on: May 17, 2016, 05:50:49 pm »
Sorry for late reply

Quote
for /f "delims=" %%i in (
    .txt) do copy "
[source]\%%i.zip" "[destination]"

[source] is just directory where You have roms ie. F:\roms, [destination] is place where You will be store copied files ie. P:\roms and
    is your file where You have rom list (without extension). Loop for will basically copy files according to content in
      .txt.

      Just put this simple function in txt file and named it for example copy_roms.cmd
[/list]