Build Your Own Arcade Controls Forum

Main => Main Forum => Topic started by: rodneykristy on May 17, 2016, 08:29:15 am

Title: Need help writing a .bat file
Post by: rodneykristy 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.
Title: Re: Need help writing a .bat file
Post by: haynor666 on May 17, 2016, 08:44:15 am
Code: [Select]
for /f "delims=" %%i in ([list].txt) do copy "[source]\%%i.zip" "[destination]"
Title: Re: Need help writing a .bat file
Post by: rodneykristy 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
Title: Re: Need help writing a .bat file
Post by: johnrt 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
Title: Re: Need help writing a .bat file
Post by: johnrt 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
Title: Re: Need help writing a .bat file
Post by: yamatetsu 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.
Title: Re: Need help writing a .bat file
Post by: haynor666 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 [/list]