中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-28 10:52
47,813 topics / 349,918 posts / today 0 new / 48,277 members
DOS批处理 & 脚本技术(批处理室) » Batch convert BAT format files to TXT format (please optimize)
Printable Version  4,115 / 20
Floor1 Batain Posted 2008-05-16 19:41
初级用户 Posts 11 Credits 24
Batch converting BAT format files to TXT format (batch renaming extensions)

Function: Batch convert BAT and CMD format batch files in the current directory to TXT format.
Purpose: Suitable for converting batch files and placing them on a mobile phone to view as TXT e-books. Since it is cumbersome to manually change the extensions when there are many files, I thought of using P to handle it. Here is the code:

The above code is not concise. Please provide a better solution. Try to make the code concise and user-friendly. It is best to add a function to restore to the original state after conversion. Of course, a backup function is even better. I hope experts can add some personalized functions such as adding a progress bar, displaying progress, and displaying processing details to make it more user-friendly. Thank you! Because my DOS is very shallow, I feel difficult even to solve small problems. Thank you.

[ Last edited by Batain on 2008-5-17 at 02:25 PM ]
Floor2 slore Posted 2008-05-16 19:52
铂金会员 Posts 2,478 Credits 5,212
ren *.cmd *.txt
ren *.bat *.txt
Floor3 gahoo Posted 2008-05-16 19:55
初级用户 Posts 19 Credits 45
Floor4 gahoo Posted 2008-05-16 19:55
初级用户 Posts 19 Credits 45
Floor5 Batain Posted 2008-05-17 14:30
初级用户 Posts 11 Credits 24
I'm sorry, I didn't make my question clear. I mean I need to solve a more optimized code for bat2txt. Because I posted this thread not just for the purpose of realizing the conversion, but to seek some more optimized and personalized solutions. The methods of the friends on the 2nd and 3rd floors are not suitable for writing into batch files, because they will even change their own suffixes, and the files that cannot be changed should also explain the reasons, otherwise it will cause misunderstandings. I hope you can give batch file codes with transparent functions and user-friendly operations for everyone to learn. We are willing to wait for the solutions from the experts at any time, but don't provide incomplete methods in a hurry. Thank you.

[ Last edited by Batain on 2008-5-17 at 02:38 PM ]
Floor6 Batain Posted 2008-05-17 14:43
初级用户 Posts 11 Credits 24
I can't understand what the friend on the fourth floor means. The CN-DOS forum is not a water-spamming forum. We believe everyone will read every reply carefully, not just the posts on the first page. I hope you don't have a guard against everyone. Believe us. If your answer is wonderful, we will collect it and we will remember you. After all, this is the first post I posted in this forum. I will be very happy if there is no reply, but I hate seeing irresponsible replies.

[ Last edited by Batain on 2008-5-17 at 02:45 PM ]
Floor7 HAT Posted 2008-05-17 14:46
版主 Posts 5,017 Credits 9,023
It's not that someone else's method is imperfect, but that your problem isn't clearly described.
Floor8 HAT Posted 2008-05-17 14:49
版主 Posts 5,017 Credits 9,023
The friend on the 4th floor means that the method he thought of was posted by the 2nd floor friend first, and there's no other meaning. The thread starter doesn't need to mind. Wish the thread starter smooth study in this forum.
Floor9 fengzi Posted 2008-05-17 15:47
中级用户 Posts 152 Credits 315
Are you from Chongqing, upstairs?
I'm from Shapingba, heh heh
Floor10 slore Posted 2008-05-17 16:02
铂金会员 Posts 2,478 Credits 5,212
Why put it in the same directory... Put it in the parent directory. You can add the path in the bat. That's simple... Or... Directly register a new type...

[ Last edited by slore on 2008-5-17 at 04:08 PM ]
Floor11 Batain Posted 2008-05-18 12:34
初级用户 Posts 11 Credits 24
Thanks for your sincerity! Also thanks to the friend on floor 7 for the method. It's the same dir command, and you used it concisely and flexibly. If there are many kinds of suffixes, it can be easily added. Also, may I ask everyone what the command to refresh the folder is? If there are hundreds or thousands of files whose suffixes need to be changed, it's best to change part of them first, then automatically refresh the folder, and then change the rest, so that friends with low machine configurations won't feel stuck.. Hehe, thanks you all!
Floor12 moniuming Posted 2008-05-18 14:20
银牌会员 Posts 574 Credits 1,335 From 广西
Use PING to pause. Pause for a few seconds every 10 times
Floor13 HAT Posted 2008-05-18 15:54
版主 Posts 5,017 Credits 9,023
I changed thousands of files at one time and didn't find it stuck. I think modifying in batches like this will反而affect the execution efficiency.

(注:原句中“反而”不需要翻译,直接保留英文形式即可,整体按照要求翻译)
Floor14 Batain Posted 2008-05-19 14:04
初级用户 Posts 11 Credits 24
Heheh! Thank you all. The method on floor 12 is very useful, but I don't understand the principle. I still don't know how to extend variables for delay. I will find materials to study when I have time; also, I found that the code styles you posted are very beautiful, with indentation and alignment very hierarchical. What editor are you using? Or do you indent manually with spaces or TABs?

Recently, I've been busy and haven't had time to focus on studying. I only come to the forum to check replies when I'm online. Friends from Sichuan and Chongqing on the upper floors, are your families all safe? I heard that there were too many shoddy houses in Sichuan during this earthquake. Now many builders cut corners, really there's no way.

[ Last edited by Batain on 2008-5-19 at 02:06 PM ]
Floor15 gahoo Posted 2008-05-19 17:04
初级用户 Posts 19 Credits 45
Almost discouraged by the LZ...

I'll do another one



Save as a batch file, then drag the folder where the batch files to be renamed are located onto this batch file, so as to solve the problem of being renamed to txt yourself

Note that there should be no spaces in the path

I feel that using for is still inefficient... so it's better to just use ren directly

[ Last edited by gahoo on 2008-5-19 at 05:17 PM ]
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023