Source: Yellow River Bank
Website: http://hhstone.vip.sina.com
Link: 《A Faster Method for Converting TXT to HTML》
Description: From the perspective of batch processing technology, the original text has not very high value; but from the practical application perspective, it still has great value. In addition, a friendly reminder: without the attached files provided in the text, it is impossible to achieve this conversion process relying solely on the program code.
[ Last edited by willsort on 2005-11-25 at 19:05 ]
Website: http://hhstone.vip.sina.com
Link: 《A Faster Method for Converting TXT to HTML》
Description: From the perspective of batch processing technology, the original text has not very high value; but from the practical application perspective, it still has great value. In addition, a friendly reminder: without the attached files provided in the text, it is impossible to achieve this conversion process relying solely on the program code.
A Faster Method for Converting TXT to HTML
Converting text to web pages and web pages to text is the most common conversion on the computer network.
How to make the conversion more convenient and faster has always been one of the popular topics in computer technology.
For example, when searching for information on the Internet and finding useful web pages, generally, they are saved as HTML files. However, saving text materials as HTML files occupies too much space, and only a very small part of the useful text materials is included. But if it is saved as a TXT file, reading is not very pleasant.
There are also some TXT format CD directory files that need to be converted to HTML files, and there are a large number of them, and a lot of time is spent on this every month.
Therefore, I always want to find a faster conversion method. I hope to be able to do:
1. Just click on an item in the right-click menu of a folder, and all the TXT files below it can be quickly converted to HTML files.
2. Copy multiple TXT files to a folder, and just type a line of commands in the command line, and any one or all of them can be converted to HTML files.
3. The program should be simple and easy to understand.
4. The program should preferably be open for easy modification and improvement.
Question: Can a fast conversion method from TXT to HTML be achieved?
Answer: There are many conversion methods from TXT to HTML, and various professional software have their own characteristics. But to achieve the above requirements, it is不妨 to compile it yourself. The performance is definitely not comparable to professional software, but if only sufficient is required and it is convenient to use, it is不妨 to give it a try.
To achieve the above requirements, the simplest method is to compile it with batch processing statements.
For example:
t2h.bat is for converting one or more TXT files. (Win98)
t2hpro.bat is for converting all TXT files in a folder.
It can be executed through the right-click send to menu (Win98/WinXP)
t2hxp.bat is for converting one or more TXT files. (Winxp)
First introduce the usage, then introduce the programming, for easy trial.
Usage of t2hpro.bat:
Organize the TXT files that need to be converted.
Mainly, do not be overly wide, generally keep the line width around 59 characters, which is convenient for reading.
Manual operation is accurate but relatively cumbersome.
It can be organized with the EmEditor editor. (V2.3 has the "Insert Carriage Return When Saving" function)
Adjust the window width, set "Wrap at Window Edge" and "Insert Carriage Return Character",
"Save", "Exit".
Create a shortcut for t2hpro.bat.
In the directory where the decompressed files are located, create a shortcut for t2hpro.bat.
And copy this shortcut to the sendto directory.
The location of the sendto directory:
Windows98 system: in \windows\sendto\
WindowsXP system: in \Document and Setting\Administrator name\sendto\
Copy the css and img two folders to the root directory.
It needs to be in the root directory of the disk where the TXT files to be converted are located. Otherwise, the HTML files cannot be displayed correctly.
Such as c:\css, c:\img, d:\css, d:\img, etc.
Use a new temporary directory for testing.
Copy the several example TXT files provided to a blank folder, assumed to be c:\temp1.
Switch the resource manager to c:\, select temp1, right-click, select "Shortcut t2hpro.bat",
Exit. Check the c:\temp1 folder, all TXT files should be converted to HTML files.
Usage of t2h.bat:
Create a blank folder.
Copy the several example TXT files provided to a blank folder, assumed to be c:\temp2.
Copy the relevant files to this folder.
Copy t2h.bat, 1.a (HTML file header), 3.a (HTML file tail) to this folder.
Run in the command line prompt.
In the command line prompt (MS-DOS for Win98), switch to this folder c:\temp2,
Run t2h Should display help information (both Chinese and English, convenient for use in English state),
Usage: t2h 〈Filespec(auto adds .txt Suffix)〉
Ex: t2h *
Usage: t2h 〈File name(without suffix, automatically add .txt suffix)〉
Example: t2h *
Run t2h * All TXT files should be converted to HTML files.
("t2h *" command is only applicable to Windows98, "t2hxp *" is for WindowsXP)
Run t2h 〈File name(without suffix, automatically add .txt suffix)〉
Should convert the specified TXT file.
t2h.bat program file.
rem t2h.bat Program for quickly converting TXT files to HTML files
@ echo off
: -------------------------------
if %1=="" goto msg
if %1=="/?" goto msg
: -------------------------------
if ErrorLevel 1 goto end
echo.
: -------------------------------
copy %1.txt %1
for %%f in (%1) do copy 1.a+%%f+3.a %%f.htm
del *.
: -------------------------------
echo.
echo OK .htm files .
echo.
echo .htm files have been generated, please use.
goto end
: -------------------------------
:msg
echo.
echo Usage: t2h 〈Filespec(auto adds .txt Suffix)〉
echo.
echo Ex: t2h *
echo.
echo Usage: t2h 〈File name(without suffix, automatically add .txt suffix)〉
echo.
echo Example: t2h *
echo.
: -------------------------------
:end
t2hpro.bat program file.
rem t2hpro.bat Program for quickly converting all TXT files in a folder to HTML files
@ echo off
: -------------------------------
if %1=="" goto msg
if %1=="/?" goto msg
: -------------------------------
if ErrorLevel 1 goto end
echo.
: -------------------------------
copy %1\*.txt %1\*
for %%i in (%1\*) do copy 1.a+%%i+3.a %%i.htm
del %1\*.
: -------------------------------
echo.
echo OK .htm files .
echo.
echo .htm files have been generated, please use.
goto end
: -------------------------------
:msg
echo.
echo Usage: t2hpro 〈FolderSpec〉
echo.
echo Usage: t2hpro 〈Folder name〉
echo.
pause
: -------------------------------
:end
Possible problems and handling opinions.
1. Impact on files without extensions.
The program only acts on TXT files, converting them into HTML files, and has no impact on other types of files. But for a very small number of files without extensions, it may add the.htm extension to them and delete the original files.
In order to avoid the situation of being deleted, it is recommended to change their attributes to read-only.
The specific method is: switch to the folder that needs to be converted, in the resource manager, select View | Arrange Icons | By Type. Files without extensions are ranked at the front. If not, it's okay. If there are any, right-click the menu and select Properties, and change their attributes to "Read-only".
2. Use under WindowsXP.
According to what was said earlier: "Create a shortcut for t2hpro.bat".
Find the required folder in the resource manager, right-click, select "Shortcut t2hpro.bat", and all TXT files should be converted to HTML files.
In the command prompt, when converting, converting a single file can be executed correctly, but when using the "t2h *" command, an abnormal situation occurs. This is because WindowsXP's "For" command has added a lot of functions, and some Windows98 commands may not be compatible, so some modifications need to be made. Now the adapted program is listed as follows. Please try it.
rem t2hxp.bat Program for quickly converting TXT files to HTML files (run in the command line prompt of WinXP)
@ echo off
: -------------------------------
if "%1"=="" goto msg
if "%1"=="/?" goto msg
: -------------------------------
if ErrorLevel 1 goto end
echo.
: -------------------------------
for %%i in (%1) do copy 1.a+%%i+3.a %%~ni.htm
: -------------------------------
echo.
echo OK html files .
echo.
echo html files have been generated, please use.
goto end
: -------------------------------
:msg
echo.
echo Usage: t2hxp 〈Filespec〉
echo.
echo Ex: t2hxp *
echo.
echo Usage: t2hxp 〈Full file name〉
echo.
echo Example: t2hxp *
echo.
: -------------------------------
:end
When converting with t2hxp.bat in the command prompt, use the full file name, and the rest is the same as the usage of t2h.bat.
Download program instructions.
In the downloaded program, in addition to this web page, it also includes t2h.bat, t2hpro.bat, t2hxp.bat, 1.a (HTML file header), 3.a (HTML file tail), \css, \img and several test TXT files.
Download: wy04091.zip 70 KB
He Shi compiled on September 1, 2004 and adapted on October 20, 2004.
Related links:
《How to Install and Use the New Version of UCDOS 7.33 Well?》
《Experience Exchange Using the 10-Year Edition of Computer Enthusiast》
Yellow River Bank website
: http://hhstone.vip.sina.com
: http://www.hhstone.com
[ Last edited by willsort on 2005-11-25 at 19:05 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!

