China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-17 22:38
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch convert BAT format files to TXT format (please optimize) View 3,583 Replies 20
Floor 16 Posted 2008-05-19 17:40 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Directly using `ren` cannot meet the LZ's needs.

The methods of the friends on the 2nd and 3rd floors are not applicable when written into a batch file, because it will even change its own suffix
Floor 17 Posted 2008-05-19 18:17 ·  中国 重庆 南岸区 电信
初级用户
Credits 45
Posts 19
Joined 2007-03-08 02:14
19-year member
UID 81032
Gender Male
Status Offline
Note that this later changed the current path. Please look carefully at "CD %1". If this batch file is not placed in the target directory, it will not be changed.

Please test the code first.

Save as a batch file, then drag the folder where the batch file to be batch renamed is located onto this batch file, so as to solve the problem that you yourself are also changed to txt.


However, I also found a problem. CD only changes the path, not the drive letter. Folders on non-C drives still don't work. Change it to pushd.

if "%1" equ "" exit
pushd %1
ren *.cmd *.txt
ren *.bat *.txt


[ Last edited by gahoo on 2008-5-19 at 06:31 PM ]
Floor 18 Posted 2008-05-19 18:56 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
What the original poster intended was to process in the current directory. Does using cd go against the original poster's intention?
Floor 19 Posted 2008-05-19 21:43 ·  中国 重庆 南岸区 电信
初级用户
Credits 45
Posts 19
Joined 2007-03-08 02:14
19-year member
UID 81032
Gender Male
Status Offline
Well, that makes sense. I didn't read the requirements carefully. If it's the current directory, I have to copy the batch file back and forth, which is quite troublesome. Isn't it better to directly process the files in the target directory?
Floor 20 Posted 2008-05-25 09:50 ·  中国 江苏 南京 电信
初级用户
Credits 24
Posts 11
Joined 2008-02-01 13:30
18-year member
UID 109956
Gender Male
Status Offline
Thanks. Generally, the files that need to be converted are placed in the same directory, so it's not troublesome to copy them one or two times. As long as it works, in short, all your methods are okay. This post has solved the problem for me personally. However, I still look forward to better methods appearing. I also look forward to some expert posting to share more creative methods in the future. Hehe~ Thank you all.
拙拙的跟各位学习学习,增长学问。
Floor 21 Posted 2008-06-02 01:17 ·  中国 重庆 南岸区 电信
新手上路
Credits 10
Posts 4
Joined 2008-05-31 15:37
18-year member
UID 120201
Gender Male
Status Offline
I found that the original poster is too sour. A simple REN command can handle it, and you still need to use BAT. You complicated a simple thing. The code you made is also complicated and too slow. It can clearly be done in a few lines.
@echo ren *.bat *.txt>>d:\t.bat
@echo ren 1.txt *.bat>>d:\t.bat
@echo del d:\t.bat>>d:\t.bat
d:\t.bat
Forum Jump: