@echo off
setlocal EnableDelayedExpansion
set/a "_tag=0,_num=0" && pushd "D:\AM-2.6.1\ROMlists"
echo==========================================================
echo= AM Favorites ROMlist Generator Script for Windows
echo==========================================================
if not exist .\favorites.txt (
set/p "'= - Cretating .\Favorites.txt File.."<nul & echo\
) else 2>nul (set/p "'= - Backing up your old Favorites.txt: "<nul
move/y .\Favorites.txt .\Favorites.txt.backup >nul && echo\Done^!!)
echo/- Gathering list of your Favorites: Tags-Files
for %%G in (*.tag)do set/a "_tag+=1" && for /f useback^delims^= %%i in (`
more "%%~G"`)do set/p "'=- ROM Found in File %%~nxG: %%~i"<nul & echo= & (
<con: find "%%~i;" <"%%~nG.txt" >>".\Favorites.txt" && set/a "_num+=1")
set/a "_num+=10000,_tag+=10000" && <con: call echo/- Romlist Files [tag=txt]: !_tag:~-3!
echo/- Favorites added to Disc: !_num:~-3! & echo/- ROMlist .\Favorites.txt: New && popd
endlocal & echo/- is Done!.. & timeout 3|findstr /ec:\.\Favorites\.txt "%~f0" & goto:EOF
========================================================================================
- Add a display in Attract Mode and set its ROMlist to the newly created .\Favorites.txt
========================================================================================
This script basically does the same thing as DM's Favorites ROMlist generator but
on Windows [ Shouts to him for the pi version d;) ].
How it works:
It grabs all the (tagged) favorites from every tag file, searches for them through
all the ROMlists, then generates a ROMlist called Favorites.txt Written by Steve
Sherrod, 05/20/17, as part of project HyperPie Expanded
========================================================================================
=========================================================
AM Favorites ROMlist Generator Script for Windows
=========================================================
- Backing up your old Favorites.txt: Done
- Gathering list of your Favorites: Tags-Files
- ROM Found in File Arcade.tag: 64street
- ROM Found in File Arcade.tag: mslug
- ROM Found in File Arcade.tag: 40love
- ROM Found in File Sega Genesis.tag: blkdrgon
- ROM Found in File Sega Genesis.tag: Duke Nukem 3D (Brazil)
- ROM Found in File Sega Genesis.tag: afighter
- ROM Found in File Sega Genesis.tag: airduel
- Romlist Files [tag=txt]: 002
- Favorites added to Disc: 007
- ROMlist .\Favorites.txt: New
- is Done!..
- Add a display in Attract Mode and set its ROMlist to the newly created .\Favorites.txt
64street;64th. Street - A Detective Story (World) (1991);6.91
mslug;Metal Slug - Super Vehicle-001 (1996);9.18
40love;Forty-Love (1984);0.00
blkdrgon;Black Dragon (Japan) (1987);9.40782122909
Duke Nukem 3D (Brazil);10 Super Jogos;Sega Genesis;;2002;Epyx;Compilaçao-Estratégia-Esporte;8+;;;;;;;;0.8;
afighter;Action Fighter (FD1089A 317-0018) (1986);7.00
airduel;Air Duel (Japan) (1990);6.74
1. Use /D
with the cd /D
, that makes the cmd.exe|CHDIR
enter the folder and the /Drive
pointed by argument, which will not occur without adding the /D
when it runs pointing to drive other than the current one.
cd /d "D:\AM-2.6.1\ROMlists"
Obs.: Can also replace cd /d
for pushd
, which changes the order in the folder queue to search for its commands by entering the folder passed by the argument already placing the current folder to the first in the queue/stack, and also saving the Drive Folder where it was originally executed to return when run with popd
.
pushd "D:\AM-2.6.1\ROMlists"
... ...
...seus códigos...
... ...
popd
2. The command set /a
can be used to define multiple variables already by assigning their values passed after the equals symbol, only using as delimiters, a space plus a comma (or just a comma), leaving its command to define the values of _num_favorites=0
and of _ROMlist=0
:
set "variável_1=valor_1, variável_2=valor_2, variável_3=valor_3"
rem :: Ou sem o espaço
set "variável_1=valor_1,variável_2=valor_2,variável_3=valor_3"
Obs.: The variable romlist
is delcarada set /a romlist=0
but does not figure in use in your code posted...
3. The original author of the code used a if exist favorites.txt()
without a else()
, ignoring (for some reason), the possible absence of the file or an action of deletion of the file by the user, which make false the message Backing up old favorites.txt file
present at first run, or for when user resolve to delete that file.
4. The command set /a "variavel=variavel + 1"
may be replaced by set /a "variável+=1"
to apply the increment of its variable (to decrease just reverse the signal set /a "variavel-=1"
).
5. The loopings For
(1x) and For /F
(2x) used in the original bat are very slow, they will catch a Mesmonomearquivo.TAG
and compare row by row with each row of Mesmonomearquivo.TXT
.
6. You can change the loop to search the other file (all at once):
listar o linha por linha do arquivo.tag
... for /f "usebackq delims=" %%i in (`more "%%~G"`)do (
...
procurar a linha do arquivo.tag no arquivo.txt de uma vez já gravando o resultado
find "%%~i;" <"%%~nG.txt">>".\Favorites.txt"
...
Obs.: But note that this will speed up processing between the two files, if the Mesmonomearquivo.TAG
has 10 lines and the Mesmonomearquivo.TXT
has 1,000 lines, so above, will be 10 lines x 1 file = 10 runs, and in the original is being 10 lines x 1000 lines = 10,000 runs, it is very time consuming.
7. Use of quotation marks, remember what @Ricardo Bohner...
In that part: echo."!str!" | findstr /c:%%a>nul && (
tries to put an quotation mark on %%a
-> "%%a"
Obs.: The Finstr
will interpret the contents of the string passed as a Regex (. *, $, ^, , 9-0, <, />, [, ], etc...
, because it tends and treats everything like Regex (unless you use one of the explicit flags so it doesn’t, or the /L
or the /C:
), and also his For /F
will immediately close the loop/loop in progress if the string contains any )
:
64street;64th. Street - A Detective Story (World);Arcade;;1991;C.P. Brain;Briga de rua-Luta / 2.5D-Luta;1-2;;;;;;;;0.5;;;;;Duken
8. Replace the Findstrt
by a find
"simple*, it is easier to use the find
for a literal search, where no regex is in use.
find "string/linhaDo.Tag" redireciona o arquivo.TXT // para o find ler na busca pela string...
find "%%~i;" <"%%~nG.txt"
9. Use quotes in your loop for /F
adding usebackq
, or abbreviated (undocumented) useback
:
Obs.: Because of my paranoia, I also use it in some codes where special characters can appear in the processing, and yet, I will use the set /p "'=String Com Caracteres Especias [espacos] , &, (, ), etc.. " <nul
, but as this causes the output of the next command to occur on the same line, I am obliged to add a echo\
when it is necessary to write on screen/file already breaking the current line. See this in the first code posted, (code in a compact version):
rem :: uso do usebackq no loop For /F aplica-se em echo, set, etc...
rem :: e o uso do set /p "'=String Escapada" <nul escapando as strings
rem :: com aspas duplas "usecakq" + set /p "=String" mas sem ecoar/printar
rem :: a duplicidade da aspas duplas: ""..."" em: ""String escapada""
for /f useback^delims^= %%i in (`
more "%%~G"`)do set/p "'=- ROM Found in File %%~nxG: %%~i"<nul & echo= & (
<con: find "%%~i;" <"%%~nG.txt" >>".\Favorites.txt" && set/a "_num+=1")
10. Same code, but ported to a more version/layout covencional:
@echo off
set /a "_tag=0"
set /a "_num=0"
cd /d "D:\AM-2.6.1\ROMlists"
setlocal EnableDelayedExpansion
echo==========================================================
echo= AM Favorites ROMlist Generator Script for Windows
echo==========================================================
if not exist .\favorites.txt (
set /p "'= - Cretating .\Favorites.txt File.."<nul
echo\
) else (
set /p "'= - Backing up your old Favorites.txt: "<nul
move /y .\Favorites.txt .\Favorites.txt.backup 2>nul >nul
if %errorlevel% equ 0 echo\Done^!!
)
echo/- Gathering list of your Favorites: Tags-Files
for %%G in (*.tag)do (
set /a "_tag=!_tag! + 1"
for /f "usebackq delims=" %%i in (`more "%%~G"`)do (
set/p "'=- ROM Found in File %%~nxG: %%~i"<nul
echo=
find "%%~i;" <"%%~nG.txt" >>".\Favorites.txt"
if %errorlevel% equ 0 set /a "_num=!_num! + 1"
)
)
set /a "_num=!_num! + 1000"
set /a "_tag=!_tag! + 1000"
call echo/- Romlist Files [tag=txt]: !_tag:~-3!
echo/- Favorites added to Disc: !_num:~-3!
echo/- ROMlist .\Favorites.txt: New
endlocal
echo/- is Done!..
findstr /ec:\.\Favorites\.txt "%~f0"
goto :EOF
========================================================================================
- Add a display in Attract Mode and set its ROMlist to the newly created .\Favorites.txt
========================================================================================
This script basically does the same thing as DM's Favorites ROMlist generator but
on Windows [ Shouts to him for the pi version d;) ].
How it works:
It grabs all the (tagged) favorites from every tag file, searches for them through
all the ROMlists, then generates a ROMlist called Favorites.txt Written by Steve
Sherrod, 05/20/17, as part of project HyperPie Expanded
========================================================================================
Some additional readings
In this part: echo."! str!" | findstr /c: %a>nul && ( tries to quote %a -> "%a"
– Ricardo Bohner
I know this does not answer the question but, pq not replace this batch with a power shell script that has thousands of more functions and would make this job a lot easier?
– Ricardo Pontual
Show!!! you found the problem in the vein, thank you very much for the help, about the poweshell I have no notion of it, could you kindly give me an example?
– arthurvalenca