tabulators

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: tabulators

#16 Post by doscode » 01 Apr 2012 01:55

Hello Aacini and thanks for your solution.

Edit1:

Code: Select all

Why do you do this?:
T:\test\_install>reg query hkcu\environment
/v temp

! REG.EXE VERSION 3.0

HKEY_CURRENT_USER\environment
    temp        REG_SZ  s:\Temp


Edit2:
OK, now I understand why the code of mine cannot work at all. I must remember that.

Edit4:
OK, I have the file. And the code works. I just must edit the tabs count calculation process, there is something wrong because long folder names are not in same level with the shorter ones.

I can change 40 to 50 but it does not help much. Do you have idea why?

Test these names in conf:
all_in_one
Východní Čechy jih
Jižní Morava střed 1 - Znojmo
Jižní Morava střed 2 - Brno, Břeclav
Jižní Morava východ 1 (Uh.Hrad.)
Jižní Morava východ 2 (Jižní Beskydy)
Jižní Morava západ - Telč
Last edited by doscode on 01 Apr 2012 05:38, edited 1 time in total.

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: tabulators

#17 Post by doscode » 01 Apr 2012 05:22

OK, so this is final code for the write script (point 3 of the task):

Code: Select all

@echo off
setlocal EnableDelayedExpansion
for /F "skip=4 delims=pR tokens=1,2" %%a in (
       'reg query hkcu\environment /v temp' ) do set TAB=%%b

del file.txt

for %%a in ("%cd%") do set "home=%%~NXa"
cd ..

IF NOT EXIST directories.conf (
   cd "%home%"
   CALL "make directory list.bat"
   cd ..
)

chcp 1250

FOR /F "delims=" %%R IN (directories.conf) DO (
   IF EXIST "%%R\scenery" (
      echo %%R
      SET "string=%%R"
      SET "#=%%R"
      SET strlen=0
      CALL :strLen
      echo LEN: !strlen!
      SET /A "counts=strlen/8"
      SET /A "remainder=strlen%%8"
      SET /A "counts=counts+1"
      REM if !remainder! gtr 0 ( SET /A "counts=counts+1" ) else ( SET /A "counts=counts+1" )
      SET /A "tabscount=(50-counts*8)/8"
      echo REMAINDER: !remainder!
      echo Tabs count: !tabscount!
      if !tabscount! equ 0 (
         if !remainder! gtr 0 (
            SET tabscount=1
         )
      )

      echo counting...
      for /L %%i in (1,1,!tabscount!) do (
         SET "string=!string!%TAB%"
      )

      echo !string!1>>%home%\file.txt

   ) ELSE (
      ECHO NOT INCLUDED %%R
   )

)

REM Echo Activation file created...
pause
goto :EOF


:strLen
if defined # ( SET "#=%#:~1%"& SET /A strlen+=1 & goto strLen )
exit /B


1st column is nice leveled.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: tabulators

#18 Post by dbenham » 01 Apr 2012 08:32

Must you use TABs? There is no standard for the display width of a tab, so something that lines up well in one text editor will look terrible in another.

If you have a process that will not work properly unless you use tabs, then fine. But if all you are trying to do is align text for display purposes, I recommend using spaces instead of tabs.


Dave Benham

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: tabulators

#19 Post by doscode » 01 Apr 2012 08:36

This is fine just as I intended. I need only notepad editor to edit activate or deactivate item in configuration file. If I would use spaces, then that would be confused with name of directory which uses spaces.

I added new feature to include line description. The description is placed in t:\test\diecrory\info_en.txt or in t:\test\diecrory\info_cz.txt

Code: Select all

@echo off
if "%1"=="en" ( SET "LANG=en") else ( SET "LANG=cz")
setlocal EnableDelayedExpansion
for /F "skip=4 delims=pR tokens=1,2" %%a in (
       'reg query hkcu\environment /v temp' ) do set TAB=%%b

del file.txt

for %%a in ("%cd%") do set "home=%%~NXa"
cd ..

IF NOT EXIST directories.conf (
   cd "%home%"
   CALL "make directory list.bat"
   cd ..
)

chcp 1250

FOR /F "delims=" %%R IN (directories.conf) DO (
   IF EXIST "%%R\scenery" (
      echo %%R
      SET "string=%%R"
      SET "#=%%R"
      SET "description="
      SET strlen=0
      CALL :strLen
      REM echo LEN: !strlen!
      SET /A "counts=strlen/8"
      SET /A "remainder=strlen%%8"
      SET /A "counts=counts+1"
      REM if !remainder! gtr 0 ( SET /A "counts=counts+1" ) else ( SET /A "counts=counts+1" )
      SET /A "tabscount=(50-counts*8)/8"
      REM echo REMAINDER: !remainder!
      REM echo Tabs count: !tabscount!
      if !tabscount! equ 0 (
         if !remainder! gtr 0 (
            SET tabscount=1
         )
      )

      REM echo counting...
      for /L %%i in (1,1,!tabscount!) do (
         SET "string=!string!%TAB%"
      )

      IF EXIST "%%R\info_%LANG%.txt" (
       echo ADDING: %%R\info_%LANG%.txt
       for /F "usebackq tokens=*" %%S in ("%%R\info_%LANG%.txt") do ( SET "description=%TAB%%%S" )
      )
      echo !string!1!description!>>"%home%\activate all regions.txt"

   ) ELSE (
      ECHO NOT INCLUDED %%R
   )

)

REM Echo Activation file created...
pause
goto :EOF


:strLen
if defined # ( SET "#=%#:~1%"& SET /A strlen+=1 & goto strLen )
exit /B
Last edited by doscode on 01 Apr 2012 14:17, edited 5 times in total.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: tabulators

#20 Post by Squashman » 01 Apr 2012 10:09

doscode wrote:This is fine just as I intended. I need only notepad editor to edit activate or deactivate item in configuration file. If I would use spaces, then that would be confused with name of directory which uses spaces.

Then echo quotes around the directory names when you create the directory.conf file.

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: tabulators

#21 Post by doscode » 01 Apr 2012 13:02

I don't want to complicate the programming and editing with quotes. I like tabs it really looks good in notepad.
Last edited by doscode on 01 Apr 2012 13:21, edited 1 time in total.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: tabulators

#22 Post by Squashman » 01 Apr 2012 13:17

doscode wrote:I don't want to complicate the programming and editing with quotes. I like tabulators it really looks good in notepad.

Well I think that is a matter of opinion on over complicating it. As two people have already pointed out that you are over complicating this by using TABS.

Not sure why you continue to spell out tabulator when it is really just called a TAB.

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: tabulators

#23 Post by doscode » 01 Apr 2012 13:26

I preffer complicate programming than complicate editing. And it is hard to stop saying tabulator, when it is in my language saying so.

doscode
Posts: 175
Joined: 15 Feb 2012 14:02

Re: tabulators

#24 Post by doscode » 02 Apr 2012 02:19

Aascini helped me to finish the reading part of my reading script. I changed !TAB! for %TAB%.

[quote="Aacini"]

Code: Select all

@echo off
setlocal EnableDelayedExpansion

if "%1"=="" (
  IF EXIST "..\_install\activate all regions.txt" (
    SET FILE="..\_INSTALL\activate all regions.txt"
    echo Setting !FILE! as your configuration file
  ) ELSE (
   echo File not found. First argument is name of configuration file .txt.
   pause
  )
) else ( SET "FILE=%1")

for /F "skip=4 delims=pR tokens=1,2" %%a in ( 'reg query hkcu\environment /v temp' ) do set TAB=%%b

FOR /F "usebackq delims=%TAB% tokens=1-3" %%A IN (!FILE!) DO (
 echo A:"%%A"B:"%%B"C:"%%C"
REM echo %%L
)



file here:
http://pastebin.com/66ucy5Mh

Post Reply