Oddball: Need to make a string of "=" that changes...

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BrentNewland
Posts: 13
Joined: 17 May 2010 15:20

Oddball: Need to make a string of "=" that changes...

#1 Post by BrentNewland » 30 Mar 2011 16:52

I've got a batch file that I use for formatting a log file (made from a batch file that uses wget to download the latest copies of a bunch of software).

Code: Select all

rem @echo off

if "%1" == "" goto error
if "%1" == "sec" goto sec
if "%1" == "pro" goto pro
if "%1" == "nl" goto nl
if "%1" == "nl2" goto nl2
goto error

:sec
rem Add section title
if "%2" == "" goto error
echo ======= > log.txt
echo =%2= >> log.txt
echo ======= >> log.txt
echo. >> log.txt
echo. >> log.txt
goto end

:pro
rem Add program title
if "%2" == "" goto error
echo ==%2== >> log.txt
echo. >> log.txt
goto end

:nl
rem New Line
echo. >> log.txt
goto end

:nl2
rem New Line x2
echo. >> log.txt
echo. >> log.txt
goto end

:error
echo. >> log.txt
echo bad log.cmd usage >> log.txt
:end



It's fairly simple - I use "call log sec Tools" to add the following into log.txt:

Code: Select all

======= 
=Tools=
=======

In Notepad/Notepad_++ (which I use to view the log files), the "=" matches up with each letter, so it makes a nice block of text. But the section names aren't always 5 characters long, and I'd like to use it also for the individual program names (e.g. "BootZilla").


So, basically, I need to figure out how long %2 is, then print %2+2 equal signs to a text file (or save that amount of equal signs to a variable). Any ideas?

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

Re: Oddball: Need to make a string of "=" that changes...

#2 Post by DosItHelp » 30 Mar 2011 18:43

BrentNewland,

Try this:

Code: Select all

@echo off
set "title=Hi There (Title up to 60 characters long)"

setlocal
set "frame=%title%  ============================================================"
echo.%frame:~60%>> log.txt
echo.=%title%=>> log.txt
echo.%frame:~60%>> log.txt
endlocal

outputs:

Code: Select all

===========================================
=Hi There (Title up to 60 characters long)=
===========================================

DisItHelp? ;)

BrentNewland
Posts: 13
Joined: 17 May 2010 15:20

Re: Oddball: Need to make a string of "=" that changes...

#3 Post by BrentNewland » 31 Mar 2011 10:29

Very good! I had to add one more "=" to the long one, it was coming up one short, other than that works great. No idea how that works (I think for any advanced batch scripting I would have to use PHP).

Post Reply