Page 1 of 1
how to make bat and txt file
Posted: 30 Apr 2022 03:46
by RyderLSK
Hi, I have a problem in advance, thank you for your help
I have a bat file and in it:
START wosb /run /systray tm="+5:00:00"
I would like the hour "+5: 00: 00" to add from the txt configuration file that if I enter 4:00:00 or 4 in the txt file, it will change in the batch file?
Re: how to make bat and txt file
Posted: 30 Apr 2022 04:01
by aGerman
Could you tell about the structure of your configuration file? Does it only consist of a single line containing 4:00:00?
Steffen
Re: how to make bat and txt file
Posted: 30 Apr 2022 04:12
by RyderLSK
sorry the configuring file is config.ini and not txt if you can do ini config then please help me in it there are
[DelayWakeUp]
Time = 6000
and here I would like to download an hour from here
TimeUP = 5:00:00
if you can't z ini then how to do with a txt file, nothing will be found in it, and ini there are a few other lines below if you need to send everything
Re: how to make bat and txt file
Posted: 30 Apr 2022 04:55
by aGerman
This is certainly not foolproof. However I guess it should do the job.
Code: Select all
@echo off &setlocal
set "inifile=config.ini"
set "section=DelayWakeUp"
set "key=TimeUP"
setlocal EnableDelayedExpansion
set "inSection="
<"!inifile!" (
for /f %%i in ('type "!inifile!"^|find /c /v ""') do for /l %%j in (1 1 %%i) do (
set "line=" &set /p "line="
if defined line (
if /i "!line!"=="[!section!]" (
set "inSection=1"
) else if defined inSection (
if /i "!line:%key%=!" neq "!line!" (
set "inSection="
set "found=!line!"
)
)
)
)
)
for /f "tokens=1* delims==" %%g in ("!found!") do (
for /f "tokens=1-3 delims=: " %%i in ("%%h") do (
if "%%i"=="" (set "h=0") else set "h=%%i"
if "%%j"=="" (set "m=00") else set "m=%%j"
if "%%k"=="" (set "s=00") else set "s=%%k"
)
)
set "tm=+%h%:%m%:%s%"
ECHO start wosb /run /systray tm="!tm!"
PAUSE
Remove the ECHO and PAUSE commands if it outputs the right START command.
Steffen
Re: how to make bat and txt file
Posted: 30 Apr 2022 05:14
by RyderLSK
SET YES
[DelayWakeUp]
Time = 60000
TimeUp = 5:00:00
the program starts but does not set the time; / am I doing something wrong?
Re: how to make bat and txt file
Posted: 30 Apr 2022 05:24
by RyderLSK
Code: Select all
&setlocal
set "inifile=config.ini"
set "section=DelayWakeUp"
set "key=TimeUP"
setlocal EnableDelayedExpansion
set "inSection="
<"!inifile!" (
for /f %%i in ('type "!inifile!"^|find /c /v ""') do for /l %%j in (1 1 %%i) do (
set "line=" &set /p "line="
if defined line (
if /i "!line!"=="[!section!]" (
set "inSection=1"
) else if defined inSection (
if /i "!line:%key%=!" neq "!line!" (
set "inSection="
set "found=!line!"
)
)
)
)
)
for /f "tokens=1* delims==" %%g in ("!found!") do (
for /f "tokens=1-3 delims=: " %%i in ("%%h") do (
if "%%i"=="" (set "h=0") else set "h=%%i"
if "%%j"=="" (set "m=00") else set "m=%%j"
if "%%k"=="" (set "s=00") else set "s=%%k"
)
)
set "tm=+%h%:%m%:%s%"
start wosb /run /systray tm="!tm!"
Yes?
Re: how to make bat and txt file
Posted: 30 Apr 2022 05:27
by aGerman
Leave the first line
Besides of that, did the original code output the expected START command?
Steffen
Re: how to make bat and txt file
Posted: 30 Apr 2022 05:35
by RyderLSK
Config.ini
[DelayWakeUp]
Time = 60000
TimeUp = 05:00:00
Code: Select all
@echo off &setlocal
set "inifile=config.ini"
set "section=DelayWakeUp"
set "key=TimeUP"
setlocal EnableDelayedExpansion
set "inSection="
<"!inifile!" (
for /f %%i in ('type "!inifile!"^|find /c /v ""') do for /l %%j in (1 1 %%i) do (
set "line=" &set /p "line="
if defined line (
if /i "!line!"=="[!section!]" (
set "inSection=1"
) else if defined inSection (
if /i "!line:%key%=!" neq "!line!" (
set "inSection="
set "found=!line!"
)
)
)
)
)
for /f "tokens=1* delims==" %%g in ("!found!") do (
for /f "tokens=1-3 delims=: " %%i in ("%%h") do (
if "%%i"=="" (set "h=0") else set "h=%%i"
if "%%j"=="" (set "m=00") else set "m=%%j"
if "%%k"=="" (set "s=00") else set "s=%%k"
)
)
set "tm=+%h%:%m%:%s%"
start wosb /run /systray tm="!tm!"
starts the program but does not enter the time
as I have typed the same:
START wosb /run /systray tm="+5:00:00"
the program starts and time adds up and your bat starts but doesn't add time; /
Re: how to make bat and txt file
Posted: 30 Apr 2022 05:39
by aGerman
I've been asking about my original code (with ECHO and PAUSE still in). Does it output the expected START command with the "tm=..." set correctly?
The reason why I added those commands is to enable you to check this upfront.
Steffen
Re: how to make bat and txt file
Posted: 30 Apr 2022 05:41
by RyderLSK
start wosb /run /systray tm="+::"
Press any key to continue . . .
I click the key and nothing happens, the program does not turn on
Re: how to make bat and txt file
Posted: 30 Apr 2022 05:43
by RyderLSK
if I remove the echo before start, the program starts and the cmd window is started
Re: how to make bat and txt file
Posted: 30 Apr 2022 05:47
by aGerman
In this case the batch code doesn't read the value out of the ini file for a reason that I don't know. Is the ini file in the same directory as the batch file? Is there maybe a space behind the [DelayWakeUp] in the ini file? Difficult for me to tell without having the original file available.
Steffen
Re: how to make bat and txt file
Posted: 30 Apr 2022 06:01
by RyderLSK
hen ... it works you were right I had a space for [DelayWakeUp], thank you very much for your help
Re: how to make bat and txt file
Posted: 30 Apr 2022 06:03
by aGerman
Making the section detection a little more robust (in terms of additional spaces), but also more weak.
Code: Select all
@echo off &setlocal
set "inifile=config.ini"
set "section=DelayWakeUp"
set "key=TimeUP"
setlocal EnableDelayedExpansion
set "inSection="
<"!inifile!" (
for /f %%i in ('type "!inifile!"^|find /c /v ""') do for /l %%j in (1 1 %%i) do (
set "line=" &set /p "line="
if defined line (
if /i "!line:[%section%]=!" neq "!line!" (
set "inSection=1"
) else if defined inSection (
if /i "!line:%key%=!" neq "!line!" (
set "inSection="
set "found=!line!"
)
)
)
)
)
for /f "tokens=1* delims==" %%g in ("!found!") do (
for /f "tokens=1-3 delims=: " %%i in ("%%h") do (
if "%%i"=="" (set "h=0") else set "h=%%i"
if "%%j"=="" (set "m=00") else set "m=%%j"
if "%%k"=="" (set "s=00") else set "s=%%k"
)
)
set "tm=+%h%:%m%:%s%"
ECHO start wosb /run /systray tm="!tm!"
PAUSE
Steffen
Re: how to make bat and txt file
Posted: 30 Apr 2022 06:46
by RyderLSK
aGerman wrote: ↑30 Apr 2022 06:03
Making the section detection a little more robust (in terms of additional spaces), but also more weak.
Code: Select all
@echo off &setlocal
set "inifile=config.ini"
set "section=DelayWakeUp"
set "key=TimeUP"
setlocal EnableDelayedExpansion
set "inSection="
<"!inifile!" (
for /f %%i in ('type "!inifile!"^|find /c /v ""') do for /l %%j in (1 1 %%i) do (
set "line=" &set /p "line="
if defined line (
if /i "!line:[%section%]=!" neq "!line!" (
set "inSection=1"
) else if defined inSection (
if /i "!line:%key%=!" neq "!line!" (
set "inSection="
set "found=!line!"
)
)
)
)
)
for /f "tokens=1* delims==" %%g in ("!found!") do (
for /f "tokens=1-3 delims=: " %%i in ("%%h") do (
if "%%i"=="" (set "h=0") else set "h=%%i"
if "%%j"=="" (set "m=00") else set "m=%%j"
if "%%k"=="" (set "s=00") else set "s=%%k"
)
)
set "tm=+%h%:%m%:%s%"
ECHO start wosb /run /systray tm="!tm!"
PAUSE
Steffen
Ok, thanks later, I will check out a big thank you for your help