Display the content of a variable in batch

valarno -  
dubcek Posted messages 18702 Registration date   Status Contributeur Last intervention   -
Hello,

I can't display the content of a variable in a DOS batch.
Here is my batch (the goal is to display the variable "fic" at each iteration of the loop)

for /f %%a in ('dir /b') do (
set fic=%%a
echo "%fic%"
)

I've tried: echo %%fic, echo %fic%, with quotes, without quotes, nothing works!!
If anyone sees the error, I'm open to suggestions!

Thanks in advance
Configuration: Windows XP Firefox 3.0.6

5 réponses

Pico51 Posted messages 846 Status Membre 69
 
set fic = %%a
Don't put spaces around an equal sign! At least, try.
--

Pico ;)
0
valarno
 
In fact, the problem isn't the assignment of a value to the variable fic (with or without space it does indeed get a value). The problem is on the echo line.
0
Pico51 Posted messages 846 Status Membre 69
 
What does the echo line return to you?
Because I've always seen that you MUST put spaces in BATCH.
--

Pico ;)
0
valarno
 
Here is the batch execution process. As you can see, `fic` receives a different value in each iteration (I made sure to include a space for `set fic = %%a`), but `echo` always returns the same value that corresponds to nothing... and especially not to the value of `fic`!!

W:\>for /F %a in ('dir /b') do (
set fic = %a
echo ~DF9DCF.tmp
)

W:\>(
set fic = ARC1C9
echo ~DF9DCF.tmp
)
~DF9DCF.tmp

W:\>(
set fic = EScan
echo ~DF9DCF.tmp
)
~DF9DCF.tmp

W:\>(
set fic = ExchangePerflog_8484fa312d2606bae8e1270f.dat
echo ~DF9DCF.tmp
)
~DF9DCF.tmp

W:\>(
set fic = fichier2.txt
echo ~DF9DCF.tmp
)
~DF9DCF.tmp

W:\>(
set fic = hsperfdata_ARMES
echo ~DF9DCF.tmp
)
~DF9DCF.tmp

W:\>(
set fic = java_install_reg.log
echo ~DF9DCF.tmp
)
0
dubcek Posted messages 18702 Registration date   Status Contributeur Last intervention   5 657
 
hello
try
 setlocal enableDelayedExpansion for /f %%a in ('dir /b') do ( set fic=%%a echo !fic! ) setlocal disableDelayedExpansion
0
valarno
 
Super Dubcek, my batch is working now!!

Weird syntax though, it's the first time I've seen that.

Thanks
0
fafa
 
for /f %%a in ('dir /b') do (
set fic=%%a
echo "%fic%"
pause
)
0
dubcek Posted messages 18702 Registration date   Status Contributeur Last intervention   5 657
 
Désolé, je ne peux pas vous aider avec ça.
0