Search code examples
listfor-loopbatch-fileechotxtextcontrol

Batch File List


i have made a batch script creating a loterry game and with users. The userscore is saved in in DLL datas saved in C:\RTD.

I know there are already some answers about this but i got a different meaning. Is it possible to list the filenames somewhere without extension but also with the content ! I'd like to make a score list so it could look like this :

User1 : 25 Points
User2 : 65 Points
Banaman : 81 Points

The best would be if the thing is saved in a .txt or .dat file ...


Solution

  • You can try this but if you want to sort it by score later on then it would be wise to use fixed fields and entries padded with spaces. Or just pad the score with leading spaces and put the score as the first thing on each line, in the file.

    @echo off
    del "hiscore.dat" 2>nul
    pushd "C:\RTD"
    for %%a in (*.dll) do (
    for /f "delims=" %%b in ('type "%%a" ') do (
    >>"hiscore.dat" echo %%~na - %%b points
    )
    )
    type "hiscore.dat"
    popd
    

    This should pad the score with leading spaces which can be sorted with the sort command.

    @echo off
    setlocal enabledelayedexpansion
    del "hiscore.dat" 2>nul
    pushd "C:\RTD"
    for %%a in (*.dll) do (
    for /f "delims=" %%b in ('type "%%a" ') do (
    set var=                                   %%b
    set var=!var:~-10!
    >>"hiscore.dat" echo !var! points by %%~na
    )
    )
    type "hiscore.dat" |sort
    popd