does the variable ‘var’ gets destroyed before displaying its value?
@echo off
FOR /f "tokens=* delims=" %%G IN ('dir') DO (
set var=%%G
echo %var%
)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This will never work since the reference to
%var%is resolved when the body of the loop is parsed. You have to enable delayed variable expansion and use!var!instead:You can read all about it by type
SET /?at a command line 😉