开发者

Bat To ini converter

Basically what I want to do is rename the batch file to .ini instead of .bat and put 1= for the first line and 2= before the second and so on and so on.

My batch file:

@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

and my result is this when I use a random text file:

1=lol1

1=lol2

1=lol3

1=lol4

2=lol开发者_JAVA百科1

2=lol2

2=lol3

2=lol4

3=lol1

3=lol2

3=lol3

3=lol4

and what I want is this:

1=lol1 

2=lol2

3=lol3

while the original .txt is:

lol1

lol2

lol3

lol4

so it basically works but it does not stop at the end of the first line it writes it writes the whole file how do I solve this? Cause I'm out of options.


answer found sry but this works better for me maybe this will help someone tho's. Finished product below.

@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


Here you go champ. If you would want some explanation, just ask

@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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜