您好我设法获取下面的代码来创建一个数字列表,并在每个数字的末尾放置一个逗号但是,事实证明,将它们放在由{{分隔的同一行上是相当挑战的1}}
,[space]
所以我现在的输出是
@ECHO OFF
setlocal EnableDelayedExpansion
set _Output=%UserProfile%\Desktop\NumGen.txt
::only change these three lines
set "start=1" ::starts from this number
set "amount=10" ::amount of files created
set "length=5" ::length of fileNames
set "join_with=, " ::what to join each number with
set /a "last=%start%+%amount%"
for /l %%i in (%start%,1,%last%) do (
set "folderName=0000000000%%i"
set "folderName=!folderName:~-%length%!%join_with%"
>>"%_Output%" ECHO.!folderName!
)
pause
但是我希望它是
00001,
00002,
00003,
00004,
00005,
00006,
00007,
00008,
00009,
00010,
00011,
我有windows 10 64bit。任何帮助将不胜感激
答案 0 :(得分:3)
echo
无法做到这一点。但是有一种解决方法,(ab)使用set
命令:
for /l %%i in (1,1,5) do (
<nul set /p "=%%i, "
)
echo(
答案 1 :(得分:1)
Stephan有一个SET / P解决方案。另一种选择是在环境变量中构建整个字符串,然后在循环结束后写入。这明显更快,但如果最终字符串长度超过~8191字节,它将失败。
set "str="
for /l %%i in (%start%,1,%last%) do (
set "folderName=0000000000%%i"
set "str=!str!!folderName:~-%length%!%join_with%"
)
>>"%_Output%" ECHO.!str!
如果您愿意,可以删除不需要的跟踪,
:
>>"%_Output%" ECHO.!str:~0,-2!