willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『楼 主』:
转贴:找txt到html更快捷的转换方法
使用 LLM 解释/回答一下
来源:黄河之滨 网站 : http://hhstone.vip.sina.com
链接: 《找txt到html更快捷的转换方法》
说明:原文从批处理技术的角度来看,价值不是很高;但是从实际应用上看,还是有很大价值的。另外友情提示一下,没有文中提供的附件,仅依赖程序代码是无法实现这个转换过程的。
找txt到html更快捷的转换方法
文本转换为网页,网页转换为文本,是电脑网络最常见的转换。
如何使转换更方便、更快捷,一直是电脑技术的热门话题之一。
如网上搜索资料,找到有用的网页,一般都是另存为html文件,
但文字资料保存为html文件,占用空间太多,有用的文字资料只占
很少的部分。但要是保存为txt 文件,阅读又不太悦目。
还有一些txt格式的光盘目录文件,也需要转换为html文件,
数量不少,每月都要为此花费不少时间。
因此总想找到一种更快捷的转换方法。希望能够做到:
1.只要点击一个文件夹的一项右键菜单,就能把它下面的txt
文件全部快速转换为html文件。
2.把多个txt文件复制到一个文件夹,只要在命令行键入一行
命令,就能把任意一个或全部转换为html文件。
3.程序要简单,容易看懂。
4.程序最好能公开,便于修改完善。
问:txt到html的快捷转换方法,能否做到?
答:txt到html的转换方法很多,各种专业软件各具特色。但要实
现以上要求,不妨自己编。性能肯定没法和专业软件比,但如果只
要求,够用就行,用起来方便,则不妨一试。
要实现以上要求,最简便的方法是用批处理语句来编。
例如:
t2h.bat 是转换一个或多个 txt文件的。(Win98)
t2hpro.bat 是转换一个文件夹内全部 txt文件的。
可以用右键发送到菜单执行 (Win98/WinXP)
t2hxp.bat 是转换一个或多个 txt文件的。(Winxp)
先介绍用法,后介绍编程,便于试用。
t2hpro.bat 的用法:
整理需要转换的txt文件。
主要是不要超宽,一般保持行宽在59个字符左右,便于阅读就行。
手工做准确,但比较繁琐。
可以用EmEditor编辑器整理。(V2.3 有"保存时插入回车换行"功能)
调整好窗口宽度,设定"在窗口边沿换行"和"插入回车换行符",
"保存","退出"。
新建t2hpro.bat的快捷方式。
在解压后文件所在的目录,新建t2hpro.bat的快捷方式。
并将这个快捷方式复制到 sendto 目录。
sendto 目录的位置:
Windows98系统:在 \windows\sendto\
WindowsXP系统:在 \Document and Setting\管理员名\sendto\
将css和img 两个文件夹复制到根目录。
需要转换为 html 文件所在磁盘的根目录。否则html文件无法
正确显示。
如 c:\css,c:\img, d:\css,d:\img,...
用新建临时目录进行测试。
将所带的几个 txt 文件实例,复制到一个空白文件夹,假定为
c:\temp1。
资源管理器切换到c:\ ,选中temp1,按右键,选"快捷方式t2hpro.bat",
退出。 检查c:\temp1 文件夹,所有的txt文件,应都转换为html文件。
t2h.bat 的用法。
新建空白文件夹。
将所带的几个 txt 文件实例,复制到一个空白文件夹,假定为
c:\temp2。
复制有关文件到此文件夹。
将 t2h.bat,1.a(html文件头),3.a(html文件尾),复制到此文
件夹。
在命令行提示符下运行。
在命令行提示符下(Win98为MS-DOS下),切换到此文件夹c:\temp2,
运行 t2h 应显示帮助信息(中英文,便于在英文状态下使用),
Usage: t2h 〈Filespec(auto adds .txt Suffix)〉
Ex: t2h *
用法: t2h 〈文件名(不加后缀,自动加 .txt 后缀)〉
例: t2h *
运行 t2h * 所有的txt文件,应都转换为html文件。
("t2h *" 命令仅适用于 Windows98,"t2hxp *" 用于 WindowsXP )
运行 t2h 〈文件名(不加后缀,自动加 .txt 后缀)〉
应转换指定的txt文件。
t2h.bat 程序文件。
rem t2h.bat txt文件快速转换为html文件程序
@ 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 文件已经生成,请使用。
goto end
: -------------------------------
:msg
echo.
echo Usage: t2h 〈Filespec(auto adds .txt Suffix)〉
echo.
echo Ex: t2h *
echo.
echo 用法: t2h 〈文件名(不加后缀,自动加 .txt 后缀)〉
echo.
echo 例: t2h *
echo.
: -------------------------------
:end
t2hpro.bat 程序文件。
rem t2hpro.bat 一个文件夹中全部txt文件快速转换为html文件程序
@ 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 文件已经生成,请使用。
goto end
: -------------------------------
:msg
echo.
echo Usage: t2hpro 〈FolderSpec〉
echo.
echo 用法: t2hpro 〈文件夹名〉
echo.
pause
: -------------------------------
:end
可能出现的问题及处理意见。
1.对无扩展名文件的影响。
程序只对txt 文件作用,将它们转换成 html文件,对其它类型
的文件没有影响,但对极少数无扩展名文件,则可能将它们加上.htm
扩展名,而删去原文件。
为了避免被删的情况发生,建议将它们的属性改为只读。
具体做法是:切换到需转换的文件夹后,在资源管理器
中,选 查看 |排列图标 |按类型 。没有扩展名的文件排在
最前面。如果没有就算了,如果有,就按右键菜单选属性,
将其属性改为"只读"就可以了。
2.在WindowsXP下使用。
按照前面所说:"新建t2hpro.bat的快捷方式"。
资源管理器找到所需文件夹,按右键,选"快捷方式t2hpro.bat",
所有的txt文件,应都转换为html文件。
在命令提示符下,转换时,转换一个文件,能够正确执行,但
在使用" t2h * "命令时,却出现异常情况。这是因为 WindowsXP
的 "For" 命令增加了不少功能,有些 Windows98 命令可能不兼容,
因而要作些修改。现将改编后的程序列出如下。请试用。
rem t2hxp.bat txt文件快速转换为html文件程序 (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 文件已经生成,请使用。
goto end
: -------------------------------
:msg
echo.
echo Usage: t2hxp 〈Filespec〉
echo.
echo Ex: t2hxp *
echo.
echo 用法: t2hxp 〈文件名全名〉
echo.
echo 例: t2hxp *
echo.
: -------------------------------
:end
在命令提示符下,用t2hxp.bat 转换时,文件名使用全名,其余和
t2h.bat 用法相同.
下载程序说明。
下载程序中,除本网页外,还包括 t2h.bat,t2hpro.bat,t2hxp.bat
1.a(html文件头),3.a(html文件尾),\css,\img 和几个供测试用的
txt 文件。
下载: wy04091.zip 70 KB
河石 2004.9.1 编 2004.10.20 改编。
相关链接:
《怎样安装好用好新版 UCDOS 7.33 ?》
《使用电脑爱好者10年版经验交流》
黄河之滨 网站
: http://hhstone.vip.sina.com
: http://www.hhstone.com
Last edited by willsort on 2005-11-25 at 19:05 ]
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.
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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|