Batch file Bat到ini转换器

Batch file Bat到ini转换器,batch-file,for-loop,cmd,ini,Batch File,For Loop,Cmd,Ini,基本上,我要做的是将批处理文件重命名为.ini而不是.bat,并将第一行的值设为1=,第二行的值设为2=,依此类推 我的批处理文件: @echo off color F0 cls :strt echo Drag your file in this window to make a ini from it. set /p file=File path with " " : del config.ini for /F "usebackq tokens=* delims=*" %%j

基本上,我要做的是将批处理文件重命名为.ini而不是.bat,并将第一行的值设为1=,第二行的值设为2=,依此类推

我的批处理文件:

@echo off 

color F0

cls

:strt

echo Drag your file in this window to make a ini from it.

set /p file=File path with " " :

del config.ini

for /F "usebackq tokens=* delims=*" %%j in (%file%) do echo 1=%%j>>config.ini

for /F "usebackq tokens=* delims=* skip=1" %%j in (%file%) do echo 2=%%j>>config.ini

for /F "usebackq tokens=* delims=* skip=2" %%j in (%file%) do echo 3=%%j>>config.ini

exit
当我使用随机文本文件时,我的结果是:

1=lol1

1=lol2

1=lol3

1=lol4

2=lol1

2=lol2

2=lol3

2=lol4

3=lol1

3=lol2

3=lol3

3=lol4
我想要的是:

1=lol1 

2=lol2

3=lol3
而原始.txt是:

lol1

lol2

lol3

lol4
所以它基本上是工作的,但它不会停在第一行的末尾,它会写整个文件,我该如何解决这个问题?因为我别无选择。

给你,冠军。 如果你想要一些解释,就问吧

@echo off
cls
set file=c:/mmm.txt

del config.ini
setlocal EnableDelayedExpansion
for /f "tokens=* delims=*" %%i in (%file%) do (
set variable=%%i
set num=!variable:~3,1!
echo !num!=!variable! >>config.ini
)
endlocal

goto :eof

答案找到了sry,但这对我来说更好,也许这会帮助其他人。 成品如下

@echo off
setLocal EnableDelayedExpansion
color F0
@mode con cols=52 lines=10
cls
echo Drag your file in this window to make a ini from it.
echo Remember if you type it in use "path" with the " "
echo.
set /p file=
echo.
for /F "usebackq tokens=* delims=*" %%j in (%file%) do (
set /a n+=1
if !n!==1 (
 echo !n!=%%j>config.ini
) else (
  echo !n!=%%j>>config.ini
)
)
exit