'Extract a variable from another variable in a FOR loop

:yes
SetLocal EnableDelayedExpansion
SET /P saizo="Introduzca el valor (en KB) minimo para realizar la busqueda: "
SET /A sss=%saizo%+0
IF %sss% EQU 0 (
    ECHO Valor invalido. Introduzca puros numeros.
    PAUSE
    CLS
    GOTO yes
)
forfiles /s /c "cmd /c echo @fsize @file" >"tumtum.txt"
FOR /F "tokens=*" %%I IN (tumtum.txt) DO (
    SET ae=%%I
    FOR /F "tokens=1 delims=" %%J IN ("!ae!") DO (
        SET fsf=%%J
        SET fnf=!ae:%fsf%=!
        ECHO !fnf!
    )
PAUSE
)

Description of the code: it asks you for a number (SET /P), then checks if it's a number and starts looking for the files on the path where it's being run. The machine needs to look for files that has a greater value (in KBs) and ECHO them. My only issue comes in the part of extracting both the size and full file name. Tried doing a FOR /F "tokens=1,2" but for files names with a space the values breaks up. What could be done to fix this?



Solution 1:[1]

for /f "tokens=1,*delims= " %%I in ('forfiles /s /p u:\ /c "cmd /c echo @fsize @file"') do echo size: %%I name:%%J

See the documentation about for (for /? from the prompt).

Placing the forfiles command within single-quotes makes for run the command as a source of input data.

Tokens=1* means "choose the first token, delimited by any of the delims characters, and assign it to the metavariable" (%I in this case); Choose the remaining characters on the line and assign them to the next metavariable.

forfiles is very slow. You would probably be better off using a dir/s/b command to select the filenames and %~zI to show the size of the file whose name is "%I"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Magoo