Display the content of a variable in batch

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 answers

  1. set fic = %%a
    Don't put spaces around an equal sign! At least, try.
    --

    Pico ;)
    0
    1. 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
      1. What does the echo line return to you?
        Because I've always seen that you MUST put spaces in BATCH.
        --

        Pico ;)
        0
        1. 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
      2. Contributor
        hello
        try
         setlocal enableDelayedExpansion for /f %%a in ('dir /b') do ( set fic=%%a echo !fic! ) setlocal disableDelayedExpansion
        0
        1. Super Dubcek, my batch is working now!!

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

          Thanks
          0
      3. for /f %%a in ('dir /b') do (
        set fic=%%a
        echo "%fic%"
        pause
        )
        0
        1. Contributor
          Désolé, je ne peux pas vous aider avec ça.
          0