我想让cmd在自己的变量中键入所有文件。 例如:
C:\>dir/b systemlogs.txt projects.bat C:\>echo %file1% systemlogs.txt C:\>echo %file2% projects.bat
任何提示?我可以用的任何代码吗?
答案 0 :(得分: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
答案 1 :(得分: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