batch_it wrote:But if I want to use a variable the script try to split the string of the variable and not the content of the file.
Code: Select all
set oldini="%APPDATA%\Settings.ini"
for /F "tokens=1,2 delims==" %%i in ("%oldini%") do (
echo %%i
)
The batch is doing exactly what you told it to do:
FOR /F %%i IN (file1 file2) - operates on a set of files
FOR /F %%i IN ("string") - operates on a string
FOR /F %%i IN ('command') - operates on the output of a command
Your code has the double quotes, so it is treated as a string.
But %APPDATA% may contain spaces, so you need to use double quotes to keep the filename together...
...that is what the "usebackq" option is for
FOR /F "usebackq" %%i IN ("filename1 with spaces" file2) - operates on a set of files, perhaps with spaces
FOR /F "usebackq" %%i IN ('string') - operates on a string
FOR /F "usebackq" %%i IN (`command`) - operates on a command.
Also, your oldini is already defined with double quotes, so "%oldini%" expands to ""somePath"" - not what you want.
Try:
Code: Select all
set oldini="%APPDATA%\Settings.ini"
for /F "usebackq tokens=1,2 delims==" %%i in (%oldini%) do (
echo %%i
)
Dave Benham