how to make bat and txt file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
RyderLSK
Posts: 9
Joined: 30 Apr 2022 03:37

how to make bat and txt file

#1 Post by RyderLSK » 30 Apr 2022 03:46

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?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: how to make bat and txt file

#2 Post by aGerman » 30 Apr 2022 04:01

Could you tell about the structure of your configuration file? Does it only consist of a single line containing 4:00:00?

Steffen

RyderLSK
Posts: 9
Joined: 30 Apr 2022 03:37

Re: how to make bat and txt file

#3 Post by RyderLSK » 30 Apr 2022 04:12

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: how to make bat and txt file

#4 Post by aGerman » 30 Apr 2022 04:55

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

RyderLSK
Posts: 9
Joined: 30 Apr 2022 03:37

Re: how to make bat and txt file

#5 Post by RyderLSK » 30 Apr 2022 05:14

SET YES

[DelayWakeUp]
Time = 60000
TimeUp = 5:00:00

the program starts but does not set the time; / am I doing something wrong?

RyderLSK
Posts: 9
Joined: 30 Apr 2022 03:37

Re: how to make bat and txt file

#6 Post by RyderLSK » 30 Apr 2022 05:24

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?

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: how to make bat and txt file

#7 Post by aGerman » 30 Apr 2022 05:27

Leave the first line

Code: Select all

@echo off &setlocal
Besides of that, did the original code output the expected START command?

Steffen

RyderLSK
Posts: 9
Joined: 30 Apr 2022 03:37

Re: how to make bat and txt file

#8 Post by RyderLSK » 30 Apr 2022 05:35

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; /

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: how to make bat and txt file

#9 Post by aGerman » 30 Apr 2022 05:39

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

RyderLSK
Posts: 9
Joined: 30 Apr 2022 03:37

Re: how to make bat and txt file

#10 Post by RyderLSK » 30 Apr 2022 05:41

start wosb /run /systray tm="+::"
Press any key to continue . . .

I click the key and nothing happens, the program does not turn on

RyderLSK
Posts: 9
Joined: 30 Apr 2022 03:37

Re: how to make bat and txt file

#11 Post by RyderLSK » 30 Apr 2022 05:43

if I remove the echo before start, the program starts and the cmd window is started

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: how to make bat and txt file

#12 Post by aGerman » 30 Apr 2022 05:47

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

RyderLSK
Posts: 9
Joined: 30 Apr 2022 03:37

Re: how to make bat and txt file

#13 Post by RyderLSK » 30 Apr 2022 06:01

hen ... it works you were right I had a space for [DelayWakeUp], thank you very much for your help

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: how to make bat and txt file

#14 Post by aGerman » 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

RyderLSK
Posts: 9
Joined: 30 Apr 2022 03:37

Re: how to make bat and txt file

#15 Post by RyderLSK » 30 Apr 2022 06:46

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

Post Reply