user1993348
user1993348

Reputation:

getting filename in variable & echoing them

In a directory I want to get each filename into a variable and then echo the variable to the screen.

REM Example 1 works but does not put filename in variable
FOR %%F in (*.*) do (
    echo %%F
)

REM Example 2 here I try to put the filename into a variable named x but when I run it it only displays the filename of 

FOR %%F in (*.*) do (
    set x=%%F
    echo %x%
)

How can I fix this?

Upvotes: 0

Views: 36

Answers (1)

dcg
dcg

Reputation: 4219

I think you should use delayed expansion like so

@echo off
setlocal EnableDelayedExpansion
FOR %%F in (*.*) do ( set x=%%F & echo !x! )

Upvotes: 1

Related Questions