1

我想让 cmd 在它自己的变量中键入所有文件。例子:

C:\>目录/b
系统日志.txt
项目.bat

C:\>回显 %file1%
系统日志.txt

C:\>回显 %file2%
项目.bat

有小费吗?我可以使用任何代码吗?

4

2 回答 2

1

尝试这个:

@echo off &setlocal enabledelayedexpansion
set /a counter=0
for %%i in (systemlogs.txt projects.bat) do (
    set /a counter+=1
    set "file!counter!=%%i"
)
set "file"

..输出是:

file1=systemlogs.txt
file2=projects.bat
于 2013-06-03T22:01:29.997 回答
0

像这样的东西应该工作:

@echo off

setlocal EnableDelayedExpansion

cd /d "C:\some\folder"

set a=0
for %%f in (*) do (
  set /a a+=1
  set "file!a!=%%~ff"
)

set b=0
for /d %%d in (*) do (
  set /a b+=1
  set "folder!b!=%%~fd"
)

for /l %%i in (1,1,%a%) do echo %%i: !file%%i!
for /l %%i in (1,1,%b%) do echo %%i: !folder%%i!

endlocal
于 2013-06-03T21:57:16.180 回答