My goal is to load a text file into a global array, and the file contains exclamation marks. I want to then bubble sort the array, and save the contents to a new file. Unfortunately I cannot even get past loading data into an array. I tried using for loops, but it seems delayed expansion is both needed and not needed. Of course, any variables made inside the loops are local variables due to the setlocal command, correct? So once endlocal is reached (in order to toggle delayed expansion), the scope is gone. I was thinking that I need the array to be global so that I can continue manipulating it later on. (I tried to add set commands at the end of endlocal to pass the local values up to higher scope, but my attempts got me nowhere.)
setlocal enabledelayedexpansion
set /a count=0
set "file=list.txt"
echo Extracting titles and IDs...
for /f "usebackq delims=; tokens=1,2* skip=1" %%a in ("%file%") do (
set /a count+=1
setlocal disabledelayedexpansion
set "title=%%b"
set "gameid=%%a"
setlocal enabledelayedexpansion
for /f "delims=- tokens=1,2*" %%x in ("!gameid!") do (
echo %%y %%x "!title!"
set "entry[!count!]=%%y %%x !title!"
echo %count% - !count!
)
endlocal
endlocal
)
pause
The input file looks like:
ID;Title;Other;Headings;We;Dont;Need
ABC-456;My second game ever! Even better!;foo;bar;blah;blah;blah
XYZ-123;My first game ever! Yes!;foo;bar;blah;blah;blah
My end goal is to create a file in the form
123 XYZ "My first game ever! Yes!"
456 ABC "My second game ever! Even better!"
after sorting by the numerical values. If anyone could help just get through the first part (loading data into an array), that would be greatly appreciated.