2017-06-14 50 views
0

在一個目錄中,我想將每個文件名都存入一個變量,然後將變量回顯到屏幕上。獲取變量中的文件名並回顯它們

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% 
) 

我該如何解決這個問題?

+0

...一百萬的問題[延遲擴展(http://ss64.com/nt/delayedexpansion.html)... – aschipfl

回答

1

我認爲你應該使用延遲擴展像約所以

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

當它包含感嘆號時,此方法無法正確顯示文件的名稱。 – treintje

相關問題