join.txt文件中的数字列表,

您好我设法得到下面的代码来创build一个数字列表,并在创build每个数字的末尾放置一个逗号然而,它已被certificate是相当的挑战,让他们在一个由,[space]分隔的同一行,[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, 

不过,我希望它是

 00001, 00002, 00003, 00004, 00005, 00006, 00007, 00008, 00009, 00010, 00011 

我有Windows 10 64位。 任何帮助将不胜感激

echo是不能做到这一点。 但有一个解决方法,(ab)使用set命令:

 for /l %%i in (1,1,5) do ( <nul set /p "=%%i, " ) echo( 

经过了漫长的休息之后,我决定再给这个狂欢和暴风骤雨。 成功:-)

 ::CallScript @ECHO OFF CALL :ScriptA CALL :ScriptB CALL :ScriptC pause goto :eof :ScriptA @ECHO OFF setlocal EnableDelayedExpansion set _Output=%UserProfile%\Desktop\NumGen.txt ::only change these three lines set "start=1" set "amount=10" set "length=5" set "join_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! ) goto :eof :ScriptB @ECHO OFF setlocal enableextensions enabledelayedexpansion set "var=" for /f "usebackq delims=" %%a in ("%UserProfile%\Desktop\NumGen.txt") do set "var=!var!%%a" echo %var%> "%UserProfile%\Desktop\NumList.txt" goto :eof :ScriptC @ECHO OFF del "%UserProfile%\Desktop\NumGen.txt" goto :eof 

这个代码决定了开始的数字,数字的数量,数字的长度和连接, "

然后ScriptB将每个数字连接在一起, "并保存到NumList.txt

最后脚本删除NumGen.txt文件。

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!