0

I am new to batch programming. I need to traverse through all files in a directory, get the filename, assign it to a variable and then call a subroutine to perform a task. I am stuck in the first task of assigning filename to a variable. My code displays the file names correctly here

@echo off

for /R  %%f in (*.*) do (
echo %%~nf
)

when I assign the name to a variable, only one value gets printed.

@echo off

for /R  %%f in (*.*) do (
set xFilename=%%~nf
echo %%xFilename
)

I am missing some basic concept here. Please help.

rajesh
  • 1
  • 1
  • See discussion about *Delayed environment variable expansion* is `set /?`. However you are doing an unnecessary step. Pass `%%F` to the function. See `call /?`. –  Jul 09 '16 at 10:14
  • either just `echo %%~nf` or with [delayed expansion](http://stackoverflow.com/a/30284028/2152082): `echo !xFilename!` – Stephan Jul 09 '16 at 13:59
  • It worked. Thanks for the response. – rajesh Jul 10 '16 at 06:29

0 Answers0