0

## BAT 編寫求助 (變數合併) (已解決)

0000_XXXX1.txt
0000_XXXX2.txt
0001_XXXX1.txt

----list----
1.0000_XXXX1.txt
2.0000_XXXX2.txt

fcount為計數
f為變數

f!fcount!為f1

fcount進1
f!fcount!為f2

%f1% echo輸出內容為 0000_XXXX1.txt

``````@echo off&setlocal enabledelayedexpansion
set basepath=D:\
set /a fcount=0

set /p a=input:

for /l %%a in (0,1,10) do (
set /a b+=1
if not "!a:~%%a,1!"=="" (
ECHO "!a:~%%a,1!"==""
set c=!b!
)
)

if %c% == 4 (
ECHO ■＝＝＝＝リスト＝＝＝＝■
For  /F  %%f in ('dir/b %a%*') do (
set /a fcount+=1
echo !fcount!.%%f
set f!fcount!=%%f
)
) else (
set /p=error
)

%f!fcount!% <--如何合併兩個變數為一個變數?

``````

``````@echo off&setlocal enabledelayedexpansion
set basepath=D:\
set /a fcount=0

set /p a=input:

for /l %%a in (0,1,10) do (
set /a b+=1
if not "!a:~%%a,1!"=="" (
ECHO "!a:~%%a,1!"==""
set c=!b!
)
)

if %c% == 4 (
For /F %%n in ('dir/b %a%*') do (
set /a fcount+=1
echo !fcount!.%%n
set f!fcount!=%%n
)
) else (
set /p=error
)

set /p u=input:
!f%u%!　<--喵的，原來是要跑！在跑％
``````

.
narumi iT邦新手 5 級 ‧ 2019-07-03 16:36:33 檢舉

https://stackoverflow.com/questions/12150065/dos-batch-nested-variable-name-using-enabledelayedexpansion
narumi iT邦新手 5 級 ‧ 2019-07-03 18:59:57 檢舉

narumi iT邦新手 5 級 ‧ 2019-07-03 19:31:06 檢舉

if %c% == 4 (
For /F %%n in ('dir/b %a%*') do (
set /a fcount+=1
echo !fcount!.%%n
set f!fcount!=%%n
)
) else (
set /p=error
)

set /p u=input:
echo !f%u%!

narumi iT邦新手 5 級 ‧ 2019-07-03 20:01:19 檢舉
!!!!
narumi iT邦新手 5 級 ‧ 2019-07-03 20:04:07 檢舉