TextToHtml.bat - Easily create World Wide Web pages!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

TextToHtml.bat - Easily create World Wide Web pages!

#1 Post by Aacini » 21 Oct 2013 00:44

When I wanted to create some web pages I first tried a couple of the "easy way" sites with disappointing results, because my main interest is to display technical data, informative tables and program code, not text in multiple fonts and colors with background images. Also, I hate that the result of any mouse-driven design depends on my skills to achieve precise mouse movements with my hand! I prefer to write code with certain parameters, test it and modify the values until I am pleased with the result. Yes, I know that I am an old-style text-oriented guy, not a modern GUI-oriented one, but in my humble opinion the write-code method produce more precise results in less time than the mouse & visual one!

Then, I passed to study HTML. After multiple jumps from innumerable HTML-related sites, I decided to create a quick reference guide that include just the most common HTML constructs. However, the "reference guide" quickly evolved into a Batch program that allows me to write just the main parts of a web page using a format similar to the one used on this forum to post topics (BBCode), and the program complete the rest. The results were so amazing that I went crazy and added more and more options until the Batch program becomes a large Text-to-HTML conversion application with a rich set of features. I also wrote an extensive documentation about the capabilities of the conversion program that is by itself a large web page with many detailed examples; I prepared several images, tables, etc. in order to complete the examples.

====================================================================================================

EDIT 2022/03/04: I modified the way to get this program. All the files are now in a single TextToHtml.zip file. Download the .zip file and extract all files in it. Then, open a cmd.exe window on the folder that contains the TextToHtml files and make a duplicate of "1-RenameMeBatAndRunMe1st.TXT" file named "1-RenameMeBatAndRunMe1st.bat" via this command:

Code: Select all

type 1-RenameMeBatAndRunMe1st.TXT > 1-RenameMeBatAndRunMe1st.bat
Do NOT use REName nor COPY commands, neither the copy-file keys (Ctrl-C + Ctrl-V) of the explorer. The purpose of this trick is fool the OS and create a .BAT file that can be executed. If you rename or copy the original .TXT file, Windows "remembers" that such a file was downloaded from the web and prevents the execution of the .BAT version. Then, execute such file just one time.

TextToHtml.zip
Last version of TextToHtml.bat program and documentation in just one .zip file
(192.81 KiB) Downloaded 431 times

EDIT 2023/05/30: I added to TextToHtml.bat program the conversion of Spanish characters áéíóúÁÉÍÓÚüÜñÑ¿¡ into HTML entities. The new code is in the .zip file below, so just download it, delete your TextToHtml.bat file and extract the new TextToHtml.bat code from the .zip file.

TextToHtml - New code.zip
Conversion of Spanish chars into HTML entities
(11.55 KiB) Downloaded 233 times

Disregard next descriptions below the line about the former method to download this program:

====================================================================================================

Finally, I used my BinToBat.bat program to pack the conversion program, the documentation and all auxiliary data in several encoded files called InstallFiles00.bat to InstallFiles10.bat that I posted here in separated replies because limitations in the size of the posted text. If you want to test my TextToHtml conversion program, download the 11 files and execute InstallFiles00.bat; you should do that in an empty folder.

EDIT: I have modified the way to download my program; it seems that the former method was too complex to follow. The TextToHtml.bat conversion program and its documentation is in the 4 .zip files placed at end of this post; download and extract them, and drag&drop "Creation of World Wide Web pages.txt" file over TextToHtml.bat just once. After that, double click on "Creation of World Wide Web pages.html" to open the documentation.

As an example of what the conversion program does, this is the first part of the text file that contain the TextToHtml.bat program documentation.

Creation of World Wide Web pages.txt:

Code: Select all

A World Wide Web page (or "internet document") is a text file written in accordance to the HyperText Markup Language (HTML) specification. When this file is placed in an internet server, it defines an "internet site" that may be reviewed by anyone that have internet access, although you do not need such access to review your own local web pages. Anyone can create a file with .html extension using a text editor like Windows Notepad, but the HTML specification is extensive and requires a certain domain knowledge in order to successfully create a web page.
[b]TextToHtml.bat[/b] is a conversion program that process a text file and translate it to a HTML file, so it allows the creation of completely functional web pages (like [i]this[/i] one) in a very simple way. The display parameters used in the created file have carefully selected default values, so the general aspect of the resulting page is very pleasant. The web elements are defined via a very simple method that allows the creation of a page in minutes, even with complex elements like lists, tables, animated images, etc. A series of optional values may be used to enrich the default appearance of any element, so the final look may be professional and complete. The only aspect that can not be changed is the general layout of the document, that resembles the [url=new:http://en.wikipedia.org/wiki/Wikipedia:Manual_of_Style/Layout]article layout of Wikipedia[/url] including a table of contents.
The elements of the web page are defined enclosing segments in the text file between special markers, called [i]tags[/i], that gives specific format to the segment; the tags are groups of equal-sign characters (like ===) or short words enclosed in square brackets (like [tag]) with the ending tag preceded by a slash (like [/tag]). For example, the contents of a file may be this one: "Normal text [tag]formatted text[/tag] more normal text"; when this file is converted and displayed in a web page, it looks this way: "Normal text [code]formatted text[/ code] more normal text".
There are four types of tags that achieve different formatting operations: 1-Document subdivisions, 2-Text attributes, 3-Hypertext links and 4-Multi-line sections. These tags are explained in this document using concise descriptions and simple examples, but the descriptions will become larger and the examples numerous as the complexity of the described tag increases. If the description of a given tag suddenly becomes too complex for you, just pass to the next tag and return to that one later; the advanced features of any tag will be comprehended in an easier way after using the basic ones.
When this text file is converted by TextToHtml.bat program, it produces this page: Image

I hope this program be useful to you.

Antonio
Attachments
Creation of World Wide Web pages 4of4.zip
(26.5 KiB) Downloaded 732 times
Creation of World Wide Web pages 3of4.zip
(94.28 KiB) Downloaded 720 times
Creation of World Wide Web pages 2of4.zip
(18.94 KiB) Downloaded 711 times
Creation of World Wide Web pages 1of4.zip
(30.34 KiB) Downloaded 716 times
Last edited by Aacini on 01 Dec 2013 12:06, edited 2 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: TextToHtml.bat - Easily create World Wide Web pages!

#2 Post by foxidrive » 20 Nov 2013 05:08

It says to me "Aacini has no public pastes."

I would suggest that you use dropbox and post a single link to the archive of the set of files.
Here is an example link using your findrepl.bat from - https://www.dropbox.com/s/rfdldmcb6vwi9xc/findrepl.bat

It doesn't need membership and the user doesn't need to do anything special to download the file.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: TextToHtml.bat - Easily create World Wide Web pages!

#3 Post by Aacini » 20 Nov 2013 09:57

Oops! I forgot to set the "public" status in the files! :evil: Fixed, thanks for the advice. :P

I had some problems when I downloaded .bat files from public sites, like your posting of FindRepl.bat. My Windows 8 refuses to execute they, even if I copy the file with other name! The only way to execute these files is via some trick, like duplicate the file with "type downloaded.bat > newname.bat". For this reason the instructions to download the files from pastebin I included in ReadMeFirst.txt file indicate to locally create the file with Notepad and copy-paste its contents, not via the "download file" button. I don't know if this method may be used in dropbox.

Antonio

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: TextToHtml.bat - Easily create World Wide Web pages!

#4 Post by foxidrive » 20 Nov 2013 20:49

Aacini wrote:I had some problems when I downloaded .bat files from public sites, like your posting of FindRepl.bat. My Windows 8 refuses to execute they, even if I copy the file with other name! The only way to execute these files is via some trick, like duplicate the file with "type downloaded.bat > newname.bat".



I wasn't aware of that... I see in Windows 8.1 it says "Unknown publisher".

But on the same dialog box is a tick you can remove so it never prompts you again.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: TextToHtml.bat - Easily create World Wide Web pages!

#5 Post by Samir » 24 Nov 2013 21:47

Very cool! So you've created a bbcode (forum code) to html parser?

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: TextToHtml.bat - Easily create World Wide Web pages!

#6 Post by Aacini » 26 Nov 2013 19:58

Yes, but this is a very extended BBCode! Did you installed the conversion program? :)

____________________________________________________________

My old FComp.bat program is a "FC command output formatter" that takes the output of FC command when compares two files (the original and a new version) and rearranges it in a much more pleasant way. The program identify new sections added between two lines of original file, or sections deleted from original file, or sections that was modified in any other way and display them in a way that allows to easily identify each case. When a section is modified the original and new versions are displayed side by side in the screen so they can be easily compared, although in this case long lines are split at half the screen.

I modified the FComp.bat program in order to store its results in a text file formatted for TextToHtml.bat conversion program, so the report on file differences will appear in a Web browser page (.html document) instead of the command-line window text screen. Although the information is exactly the same than before, the new appearance and formating makes this page much more pleasant and useful. For example, in modified sections you will see two frames in the page placed side by side, so you may review and compare the lines of the modified sections via the scroll bars of the frames no matter the size of the section.

The image below is an example of the result produced by this method:

Image

NewFComp.bat:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem FComp.bat: Format FC output in a pleasant way
rem Antonio Perez Ayala - Nov/10/2012
rem Nov/25/2013: Generate output for TextToHtml.bat conversion program

if "%~2" neq "" goto begin
echo Format FC output identifying added, deleted or modified sections
echo/
echo FCOMP same parameters and switches of FC command
goto :EOF

:begin

set while=if not
set   and=if not
set do=goto endwhile
set endwhile=goto while
set break=goto endwhile

set params=%*
set "cutNumber="
if "!params:/N=!" neq "!params!" set "cutNumber=:~8"
fc %* > differences.txt
if %errorlevel% equ 0 (
   echo FComp: no differences encountered
   del differences.txt
) else (
   set /P filename=< differences.txt
   set "filename=!filename:Comparing files =!"
   set "filename=!filename: and = to !"
   call :FormatFCOutput < differences.txt > "%~DP0!filename:.txt=!.txt"
   del differences.txt
   "%~DP0TextToHtml" "%~DP0!filename:.txt=!.txt"
)
goto :EOF


:FormatFCOutput

set "slash=/"
echo =
set /P line=
echo [color="0" size="+2"]!line![/color]
echo [hr]
set /P line=
:while  There is another set of differences
%while% defined line %do%

   set "line="
   set /P line=
   if defined line (
      set "line=!line:[=&#91;!"
      set "line=!line:|=&#124;!"
   )
   set old=0
   :while1  There is another line in this old section
   %while% "!line:~0,5!" neq "*****" %do%1

      set /A old+=1
      set "oldLine[%old%]=!line!"
      :while1.5  PATCH FOR FC GLITCH: Concatenate next line while current is 127 chars. long
      %while% defined line           %do%1.5
        %and% "!line:~126,1!" neq "" %do%1.5
         set "line="
         set /P line=
         rem                          or until this set of differences ends
         if "!line:~0,5!" equ "*****" %break%1
         if defined line (
            set "line=!line:[=&#91;!"
            set "line=!line:|=&#124;!"
            set "oldLine[%old%]=!oldLine[%old%]!!line%cutNumber%!"
         )
      %endwhile%1.5
      :endwhile1.5
      set "oldLine[%old%]=!oldLine[%old%]! "
      set "line="
      set /P line=
      if defined line (
         set "line=!line:[=&#91;!"
         set "line=!line:|=&#124;!"
      )
   %endwhile%1
   :endwhile1

   set "line="
   set /P line=
   if defined line (
      set "line=!line:[=&#91;!"
      set "line=!line:|=&#124;!"
   )
   set new=0
   :while2  There is another line in this new section
   %while% "!line:~0,5!" neq "*****" %do%2

      set /A new+=1
      set "newLine[%new%]=!line!"
      :while2.5  PATCH FOR FC GLITCH: Concatenate next line while current is 127 chars. long
      %while% defined line           %do%2.5
        %and% "!line:~126,1!" neq "" %do%2.5
         set "line="
         set /P line=
         rem                          or until this set of differences ends
         if "!line:~0,5!" equ "*****" %break%2
         if defined line (
            set "line=!line:[=&#91;!"
            set "line=!line:|=&#124;!"
            set "newLine[%new%]=!newLine[%new%]!!line%cutNumber%!"
         )
      %endwhile%2.5
      :endwhile2.5
      set "newLine[%new%]=!newLine[%new%]! "
      set "line="
      set /P line=
      if defined line (
         set "line=!line:[=&#91;!"
         set "line=!line:|=&#124;!"
      )
   %endwhile%2
   :endwhile2

   rem Identify the type of this set

   rem PATCH FOR FC GLITCH: If both versions are size 2, it is a modified section
   set /A "oldEqu2_And_NewNeq2=^!(old-2)*(new-2), newEqu2_And_OldNeq2=^!(new-2)*(old-2)"
   if %old% equ 0 (     
      echo [b]NEW SECTION ADDED AT END OF FILE[/b]
      echo [table border="0" cellspacing="0" bgcolor="Black" width="100%%"]
      for /L %%i in (1,1,!new!) do echo [color="Lime" face="Courier New, Monaco, monospace"]!newLine[%%i]![/color]
      echo [/table]
   ) else if %new% equ 0 (
      echo [b]OLD SECTION DELETED FROM END OF FILE[/b]
      echo [table border="0" cellspacing="0" bgcolor="Black" width="100%%"]
      for /L %%i in (1,1,!old!) do echo [color="Red" face="Courier New, Monaco, monospace"]!oldLine[%%i]![/color]
      echo [/table]
   ) else if %oldEqu2_And_NewNeq2% neq 0 (
      call :getBothLines[1]
      if "!oldLine!" equ "!newLine!" (
         echo [b]NEW SECTION ADDED[/b]
         echo [table border="0" cellspacing="0" bgcolor="Black" width="100%%"]
         echo [color="White" face="Courier New, Monaco, monospace"]!oldLine[1]![/color]
         set /A new-=1
         for /L %%i in (2,1,!new!) do echo [color="Lime" face="Courier New, Monaco, monospace"]!newLine[%%i]![/color]
         echo [color="White" face="Courier New, Monaco, monospace"]!oldLine[2]![/color]
         echo [/table]
      ) else (
         echo [b]NEW SECTION ADDED AT BEGINNING OF FILE[/b]
         echo [table border="0" cellspacing="0" bgcolor="Black" width="100%%"]
         set /A new-=2
         for /L %%i in (1,1,!new!) do echo [color="Lime" face="Courier New, Monaco, monospace"]!newLine[%%i]![/color]
         echo [/table]
      )
   ) else if %newEqu2_And_OldNeq2% neq 0 (
      call :getBothLines[1]
      if "!oldLine!" equ "!newLine!" (
         echo [b]OLD SECTION DELETED[/b]
         echo [table border="0" cellspacing="0" bgcolor="Black" width="100%%"]
         echo [color="White" face="Courier New, Monaco, monospace"]!newLine[1]![/color]
         set /A old-=1
         for /L %%i in (2,1,!old!) do echo [color="Red" face="Courier New, Monaco, monospace"]!oldLine[%%i]![/color]
         echo [color="White" face="Courier New, Monaco, monospace"]!newLine[2]![/color]
         echo [/table]
      ) else (
         echo [b]OLD SECTION DELETED FROM BEGINNING OF FILE[/b]
         echo [table border="0" cellspacing="0" bgcolor="Black" width="100%%"]
         set /A old-=2
         for /L %%i in (1,1,!old!) do echo [color="Red" face="Courier New, Monaco, monospace"]!oldLine[%%i]![/color]
         echo [/table]
      )
   ) else (
      if %new% gtr %old% (set height=%new%) else set height=%old%
      if !height! leq 4 (set /A height+=2) else set /A height=height*12/10+1
      if !height! gtr 32 set height=32
      echo [b]SECTION MODIFIED[/b]
      echo [code color:White; background:Black; font-size:1em; font-weight:normal; height:!height!em; width:48%%; float:left;]
      for /L %%i in (1,1,%old%) do echo(!oldLine[%%i]!
      echo [%slash%code]
      echo [code color:White; background:Black; font-size:1em; font-weight:normal; height:!height!em; width:48%%; float:right;]
      for /L %%i in (1,1,%new%) do echo(!newLine[%%i]!
      echo [%slash%code]
      echo [br clear="all"]
   )

   rem Pass to next set of differences
   set /P line=
   set "line="
   set /P line=
%endwhile%
:endwhile

echo [url=#][style="float:right; font-size:small;"]Top[/style][/url][br]

exit /B


:getBothLines[1]
set "oldLine=!oldLine[1]%cutNumber%!"
set "newLine=!newLine[1]%cutNumber%!"
exit /B


Antonio

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: TextToHtml.bat - Easily create World Wide Web pages!

#7 Post by Samir » 27 Nov 2013 08:15

Aacini wrote:Yes, but this is a very extended BBCode! Did you installed the conversion program? :)
I haven't yet as I haven't figured out exactly where I can use this, but I'm sure I will as I do work a lot with bbcode.

Your fcomp is really rad! Reminds me of windiff. How fast is it?

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: TextToHtml.bat - Easily create World Wide Web pages!

#8 Post by Aacini » 09 Dec 2013 22:56

Although the primary use of TextToHtml.bat conversion program is to create "web pages", it may also be used to generate a HTML document that present information in a more pleasant and organized way than just as text in the cmd.exe window. The format of the file required for the HTML conversion is straightforward, so a Batch program may be written in order to take a certain information and generate the intermediate file for such "web page". Previous "FCompInHtml.bat" is an example of such program.

The Batch program below takes the output of HELP command and assemble a HTML document with it; however, this program does not just gather the commands help information in alphabetical order as usual, but organizes it in a coherent way I borrowed from "Windows-DOS Commands Help" of my MENUSYS.BAT program. The Table of Contents of the created web page have these 8 chapters: Screen, File, Directory, Disk, Process, Communications, Batch and Various; when a certain chapter is extensive (like File or Batch), it is subdivided in sections. The links in this table opens "sub-tables" that lists the existent commands in each area with further links to the detailed information; this scheme allows to find the commands related to a certain topic in a very easy way, instead of reviewing the whole list of commands looking for the ones that can be applied to a given problem. Anyway, a pop-up index menu placed at beginning of the page allows to access all commands in the usual alphabetical order.

HelpToTextToHtml.bat:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem HelpToTextToHtml.bat: Create a web page with Windows-DOS commands help
rem Antonio Perez Ayala

set leftSqrBrk=[

rem Load the list of commands from Help command
for /F "skip=2 tokens=1* delims=:" %%a in ('help ^| findstr /N "^"') do (
   set "line=%%b"
   if not defined line goto endHelp
   if "!line:~0,3!" neq "   " (
      for /F "tokens=1*" %%c in ("!line!") do (
         set "help[%%c]=%%d"
         set "com=%%c"
      )
   ) else (
      for %%c in (!com!) do for /F "tokens=*" %%d in ("!line!") do set "help[%%c]=!help[%%c]! %%d"
   )
)
:endHelp

rem Delete synonyms and problematic commands from the list
for %%a in (ERASE RENAME  CHDIR MKDIR RMDIR  SC DISKPART GRAFTABL) do set "help[%%a]="

rem Process the help definition file
set /P "fileName=" < HelpToTextToHtml.txt
setlocal DisableDelayedExpansion
( rem Start of redirected block to Stdout and Stderr
echo = =
echo [hr]>&2
set "codeSeg="
set "footer="
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" HelpToTextToHtml.txt') do if %%a neq 1 (
   set "line=%%b"
   setlocal EnableDelayedExpansion

   if defined codeSeg (
      echo(!line!>&2
      if "!line:~0,7!" equ "%leftSqrBrk%/code]" (endlocal & set "codeSeg=") else endlocal
   ) else if /I "!line:~0,6!" equ "%leftSqrBrk%code]" (
      echo !line!>&2
      for %%c in (!line:~6!) do endlocal & set codeSeg=Y & set "select[%%c]=%%c"
   ) else if "!line:~0,1!" equ "=" (
      rem Subdivision: just copy it
      echo !line! > CON
      echo !line!
      if "!line:~2,1!" neq "=" for /F "delims=|" %%c in ("!line:~2!") do set "footer=!footer! %%c"
      for /F "delims=" %%c in ("footer=!footer!") do endlocal & set %%c
   ) else (
      rem Process commands in not-subdivision line
      set "com="
      echo [list]
      for %%c in ("!line: =" "!") do (
         if defined help[%%~c] (
            help %%~c > help.txt
            if /I "%%~c" equ "PAUSE" echo/>> help.txt
         ) else (
            %%~c /? > help.txt 2>NUL
         )
         for /F %%d in ('find /V /C "" ^< help.txt') do set /A height=%%d-1
         if !height! gtr 0 (
            echo Command: %%c > CON
            echo [*][url=#%%~c]%%~c[/url] - !help[%%~c]!
            set /A height=height*12/10+1
            if !height! gtr 30 (set "height= height:30.5em;") else set "height="
            echo %leftSqrBrk%code!height!]%%~c>&2
            type help.txt>&2
            echo %leftSqrBrk%/code]>&2
            set "com=!com! %%~c"
         )
      )
      echo [/list]
      echo [br][hr]>&2
      for %%c in (once !com!) do if %%c equ once (endlocal) else set "help[%%c]=" & set "select[%%c]=%%c"
   )
)

rem Process the rest of commands displayed by help command
setlocal EnableDelayedExpansion
echo [list]
for /F "tokens=2 delims=[]" %%c in ('set help[') do (
   help %%c > help.txt
   for /F %%d in ('find /V /C "" ^< help.txt') do set /A height=%%d-1
   echo Command: "%%c" > CON
   echo [*][url=#%%c]%%c[/url] - !help[%%c]!
   set /A height=height*12/10+1
   if !height! gtr 30 (set "height= height:30.5em;") else set "height="
   echo %leftSqrBrk%code!height!]%%c>&2
   type help.txt>&2
   echo %leftSqrBrk%/code]>&2
   set "select[%%c]=%%c"
)
echo [/list]
echo =
echo [br][hr]>&2

rem Create the footer
echo [list=C:3]>&2
(for %%a in (!footer!) do echo [*][url=#%%a]plain:[color="#666666" size="-1"]%%a[/color][/url]) >&2
echo [/list]>&2

) > TOCData.txt  2> bodyData.txt
del help.txt

rem Create the alphabetical index and assemble the final file
< NUL (
   set /P "=[style="float:right"]Index: [select][url]Pick command[/url]"
   set "group="
   for /F "tokens=2 delims=[]" %%a in ('set select[') do (
      if "!select[%%a]:~0,1!" neq "!group!" (
         set "group=!select[%%a]:~0,1!"
         set /P "=[url]group:!group![/url]"
      )
      set /P "=[url=#%%a]%%a[/url]"
   )
   echo [/select][/style]
   type TOCData.txt
   type bodyData.txt
) > "%filename%.txt"
del TOCData.txt
del bodyData.txt

rem Convert the file to Html
echo/
echo ------------------------------------------
echo/
TextToHtml.bat "%filename%.txt" "maxUrlTagsInSelect=120"
echo ERROR: TextToHtml.bat conversion program not found


Previous program use the data file shown below as "template" for the final web page; this method also allows the inclusion of useful additional information that can not be extracted from the commands help. This scheme may be adopted in other areas in order to take information from any program or application instead of HELP command, and present the results in a more readable HTML document.

HelpToTextToHtml.txt:

Code: Select all

Windows-DOS Commands Help
==Screen|:- Commands for Screen control==
TITLE COLOR CLS CHCP MODE GRAFTABLE
==File|:- Commands to manage Files==
===Text files|:- Process the contents of Text files===
TYPE MORE PRINT FIND FINDSTR SORT FC COMP EDIT EDLIN DEBUG
===All files|:- Process files as Entire units===
DIR TREE REN COPY XCOPY ROBOCOPY MOVE REPLACE MKLINK DEL ATTRIB CACLS ICACLS MAKECAB EXPAND PACKAGER FSUTIL
==Directory|:- Commands to create, change and remove Directories==
MD CD PUSHD POPD RD SUBST APPEND MKLINK MOUNTVOL
==Disk|:- Commands for Disk maintenance==
FORMAT LABEL VOL CHKDSK CHKNTFS CONVERT COMPACT CIPHER RECOVER DISKCOPY DISKCOMP
==Process|:- Commands to execute, list and cancel Programs==
START RUNAS AT SCHTASKS TASKLIST TASKKILL TSKILL TSSHUTDN SHUTDOWN PATH ASSOC FTYPE SETVER
==Comms|:- Commands to manage Communications==
MSG TELNET TFTP PING PATHPING NET OPENFILES DRIVERQUERY GPRESULT
==Batch|:- Values, modifiers and commands for Batch files==
===Char:Characters|:- Special Characters used in commands and Batch files===
[code]Characters
 ,;=  Separators for command parameters and FOR sets, besides spaces and tabs.
  *?  Wild-card characters that matches several file and directory names.
   @  Placed before a command does not echo it even if ECHO is ON: @ECHO OFF

   >  Send command output to a new disk file: COMMAND > OUTPUT.TXT
      The DOS waste bin is called NUL: COPY *.* DEST > NUL
  >>  Append command output if the file exists: COMMAND >> APPEND.TXT
  2>  Send error messages to a disk file: COMMAND 2> ERRORS.TXT
2>&1  Send error messages to the same file of >: COMMAND > ALL.TXT 2>&1
   <  Get command input from a disk file: COMMAND < INPUT.TXT

   &  COM1 & COM2 is the same as execute COM1 and then execute COM2
   |  COM1 | COM2 is equivalent to: COM1 > F.TMP & COM2 < F.TMP & DEL F.TMP
      but both commands run in parallel (in different cmd.exe contexts).
  &&  COM1 && COM2 is the same as: COM1 & IF NOT ERRORLEVEL 1 COM2
  ||  COM1 || COM2 is the same as: COM1 & IF ERRORLEVEL 1 COM2
  ()  Group together several commands: ( COM1 & COM2 & COM3 ) > THREEOUTS.TXT
      TESTCOM && ( COM1THEN & COM2THEN ) || ( COM1ELSE & COM2ELSE & COM3ELSE )

   %  Expand the value of Batch parameters (%1 ...), FOR parameters (%%A ...)
      and Batch variables (%VAR%); %* always expands to all Batch parameters.
      A FOR command typed in the command-line must use a single percent char.
   !  Additional way (Delayed Expansion) to take the value of a variable: !VAR!

   ^  Insert, not process, the next special character: ECHO ^%VAR^% is %VAR%
      An exclamation mark can not be inserted in a Batch file this way
      if Delayed !VARIABLE! Expansion is Enabled.
   "  Enclose a string that will not be processed as special characters:
      SET "HEADER=<ONE|TWO|THREE>"
      Exclamation marks are always processed if Delayed Expansion is Enabled.
[/code]
===Vars:Variables|:- Normal and delayed expansions, and dynamic Variables===
[code]Variables
%var%            Expand the value of Var variable: ECHO Var value is: %Var%

%var:old=new%    Substitute all occurrences of Old (case insensitive) by New
                 in Var expansion. If Old start with asterisk, substitute from
                 beginning of Var value until first occurrence of Old.

%var:~pos,size%  Substring of Var from 0-based Position by Size characters; if
                 Pos or Size are negative, indicate a backwards position from
                 end. If Size is omitted, the substring ends at last character.

A variable may be enclosed in exclamation-marks instead of percent-signs to
expand its value in Delayed Variable Expansion that happens after the normal
(percent-signs) expansion, so both types may be combined. This feature allows
some advanced manipulations, like multi-dimensional arrays. For example:

    SET /P OLD=Enter old part:
    SET /P NEW=Enter new part:
    SET CHANGED=!ORIGINAL:%OLD%=%NEW%!

    SET /P POS=Enter position:
    SET /P SIZE=Enter size:
    SET SUBSTRING=!VAR:~%POS%,%SIZE%!

    SET VECTOR[1]=Element One
    SET VECTOR[2]=Element Two, etc...
    SET I=set subscript value in some way
    ECHO The value of element %I% is: !VECTOR[%I%]!

If there are several commands in one line or enclosed in parentheses, %normal%
expansions are performed just once before the line or block is executed, but
!delayed! expansions are performed each time that the commands are executed:

    SET VAR=Old value
    SET VAR=New value & ECHO Previous value: %VAR%, modified in this line: !VAR!

In order to use Delayed Expansion, insert this command at beginning of Batch file:

    SETLOCAL ENABLEDELAYEDEXPANSION

Dynamic variables (don't define any variable with same name):

%CD%             Expands to the current directory string.
%DATE%           Expands to current date using same format as DATE command.
%TIME%           Expands to current time using same format as TIME command.
%RANDOM%         Expands to a random decimal number between 0 and 32767.
%ERRORLEVEL%     Expands to the current ERRORLEVEL value.
[/code]
===Mods:Modifiers|:- Expansion Modifiers for replaceable parameters===
[code]Modifiers
The following modifiers works in FOR command parameters (letters) and
Batch file parameters (digits); the modifiers may not be used with %*
Letter (%A..%Z) and digit (%0..%9) Parameters are represented below by: %P

%P       Expands P
%~P      Expands P removing any surrounding quotes (").
%~fP     Expands P to a Fully qualified path name.
%~dP     Expands P to a Drive letter only (including the colon).
%~pP     Expands P to a Path only (that ends in backslash).
%~nP     Expands P to a file Name only.
%~xP     Expands P to a file eXtension only (including the dot).
%~sP     Expands P using Short 8.3 names.
%~aP     Expands P to file Attributes.
%~tP     Expands P to date/Time of file.
%~zP     Expands P to siZe of file.

%~$var:P Special case: Searches current P file name in the directories listed
         in Var Batch variable and expands the parameter to the fully qualified
         path name of the first one found, or an empty string if not found.
         The directories must be separated by semicolons, like in PATH variable.

Several modifiers may be combined in the same parameter: %~ntzP

For example, the following command take the path of the running Batch file:
    SET MYPATH=%~p0
[/code]
===Error:Errorlevel|:- Description of the Errorlevel value===
[code]Errorlevel
When most commands and programs ends they return an exit code, called
ERRORLEVEL, that is a 32-bits signed integer value. The MS-DOS standard
specify that a program return an ERRORLEVEL of zero if successfully ends,
but the value is greater than zero if the program ends because an error.

The following DOS commands, among others, return useful ERRORLEVEL values:
TYPE return 0 if the file was typed, return 1 if File not found.
COPY return 0 if file(s) was copied, return 1 if File not found.
FIND return 0 if the string was found, return 1 otherwise (also FINDSTR).
FC   return 0 if both files matched, return 1 otherwise.
CD   return 0 if directory was changed, return 1 if Dir not exists.
VOL  return 0 if volume was displayed, return 1 if invalid Drive.
TIME return 0 if given time is correct, return 1 if invalid Time (also DATE).
SET /P return 1 if line read is empty, otherwise NOT change ERRORLEVEL.
SET /A return not zero if expression is wrong, otherwise NOT change ERRORLEVEL.
VERIFY return 0 if parameter is ON or OFF, return 1 otherwise.
VER  always return 0.

The following internal DOS commands, among others, does not modify the
current ERRORLEVEL value: CLS, REM, ECHO, PAUSE, SHIFT, GOTO, SET var=value
All .COM and .EXE executable files modify the ERRORLEVEL when they ends.

To check the ERRORLEVEL use "IF ERRORLEVEL Number Command" that execute the
Command if the ERRORLEVEL value is greater than or equal to the given Number;
to test for several values, place the IF's in descending ERRORLEVEL order:
FOR /L %%I IN (6,-1,1) DO IF ERRORLEVEL %%I GOTO ERROR%%I

A Batch file may directly get the ERRORLEVEL value via the %ERRORLEVEL%
dynamic variable, for example: IF %ERRORLEVEL% EQU 3 GOTO ERROR3

A Batch file may return an useful ERRORLEVEL value via "EXIT /B exitCode" command.
This is the one-line SETERRORLEVEL.BAT file that allows to set the ERRORLEVEL
to any value given in its parameter: @EXIT /B %1
For example: CALL SETERRORLEVEL 123
[/code]
===Commands|:- Commands used in Batch files===
REM ECHO PAUSE CHOICE SHIFT GOTO IF FOR SET SETLOCAL ENDLOCAL CALL CMD EXIT
==Various|:- Commands that not fit in previous subdivisions==


The following image show the first page of the HTML document (with the alphabetical index open) created with previous files:

Image


Note that HelpToTextToHtml.bat file use a couple small additional features of the conversion program that I have updated in its site before I posted this reply, so you need to download the last version of TextToHtml.bat file in order to correctly generate the "Windows-DOS Commands Help.html" document. I suggest you to also download "Creation of World Wide Web pages.txt" file and create the updated documentation of the conversion program, that explain these new features in section 1.3- "Division headers".

The conversion of "Windows-DOS Commands Help.txt" into an HTML document may take several minutes. When the text file contain certain Batch special characters the conversion is much slower, and the commands help is plenty of such characters!

Antonio

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: TextToHtml.bat - Easily create World Wide Web pages!

#9 Post by foxidrive » 10 Dec 2013 01:11

Antonio, just for the record it took me 34 mouse clicks, and concentration to get them right - to download the items on that pastebin page.

If you want people to try your great scripts out, then please consider archiving them into one ZIP file and paste the link in Dropbox or somewhere. Make it easy for your target audience.
Here's another thought - you created a script to generate a batch file that contains a set of binary files. Why not use that to bundle the scripts up and post *that* to pastebin as an extra item?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: TextToHtml.bat - Easily create World Wide Web pages!

#10 Post by Ed Dyreen » 10 Dec 2013 23:20

Aacini wrote:When I wanted to create some web pages I first tried a couple of the "easy way" sites with disappointing results
I assume you are talking about a Content Management System ?
Aacini wrote:Yes, I know that I am an old-style text-oriented guy, not a modern GUI-oriented one, but in my humble opinion the write-code method produce more precise results in less time than the mouse & visual one!
Although one can create a simple website using a CMS without having any web-programming experience, they cannot replace a lack of web-programming experience fully. Unless one learns web-programming one is always bound to the limitations of the CMS.
They are designed for creating simple designs rapidly, taking some banal work out of the hands of the programmer.

What helped me a lot was this book http://www.webstepbook.com/.
It teaches how to think and provides models that proved me helpful.
After all, knowing to code is silver, knowing how to think about code is gold. :P

Interesting TextToHtml.bat, did something similar once, translating to htm...

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: TextToHtml.bat - Easily create World Wide Web pages!

#11 Post by foxidrive » 05 Mar 2014 06:09

I saved the files from this project way back when you posted this Aacini, and I wanted to have a look today but I found several issues with the process and I can't get it to run without debugging.

The filenames are saved from the original pastebin site with underscores instead of spaces, and I seem to have solved that, but it still won't run correctly.
I don't know if it is my error during saving but I think I saved them all as RAW so they should be fine.

It seems to install ok, I don't get any prompt messages from Firefox, but I get recurring strings of this amongst legitimate text on the HTML page in my Firefox web browser.

Code: Select all

¿" was unexpected at this time. ¿" was unexpected at this time. ¿" was unexpected at this time. ¿" was unex


The original source files I have are in the zip file here on my FTP server if you are interested in figuring out the problem, but
can you please upload a copy of the working files to my FTP server or make them available as a single ZIP download somewhere?

Here's the FTP server address: ftp:// >nul

Username: dostips
Password:foxi

Thanks
foxi

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: TextToHtml.bat - Easily create World Wide Web pages!

#12 Post by foxidrive » 13 Mar 2014 06:39

Did anyone get the code in this thread to work at all?

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: TextToHtml.bat - Easily create World Wide Web pages!

#13 Post by Aacini » 13 Mar 2014 12:54

I just made a test with the files on that site. This is what I did:

  • Read the ReadMeFirst.txt file
  • I downloaded the files following the instructions of the ReadMeFirst.txt file: after open each file, select RAW, then press Ctrl-A, Ctrl-C and close it, then select the destination file and Ctrl-V. Although the procedure is a little cumbersome, I downloaded all 10 files in about 8 minutes. I don't entered the name of each file when I created they, but copy-pasted they from the list in ReadMeFirst.txt file.
  • I double-clicked on InstallFiles.bat. After about 6 minutes, the command-line screen said "Press any key to continue"
  • I pressed a key and the first page of "Creation of World Wide Web pages" appear. I clicked on "Allow blocked contents".

As long as I can see, everything is OK. I use Windows 8.1 and Internet Explorer 10.

Although I tested the created web pages in Internet Explorer 8 and 10 only, when I developed the conversion program I carefully choose just those features that a comparison table reported to work the same in several browsers.

Antonio

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: TextToHtml.bat - Easily create World Wide Web pages!

#14 Post by foxidrive » 14 Mar 2014 04:08

Aacini wrote:I just made a test with the files on that site. This is what I did:

Although the procedure is a little cumbersome


Yes, it is. I did the same thing. It doesn't work.

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: TextToHtml.bat - Easily create World Wide Web pages!

#15 Post by Matt Williamson » 28 Mar 2014 06:20

I can't get them to work either but even so, it's worth it to grab all of them because there are some real gems in the code to study. I'd love to get the HTML help file that should be produced but it just hangs at a certain part of the script every time I run it.

Post Reply