|
Batain
初级用户
 
积分 24
发帖 11
注册 2008-2-1
状态 离线
|
『楼 主』:
批量将BAT格式文件转成TXT格式(请优化)
使用 LLM 解释/回答一下
将BAT格式文件批量转成TXT格式(批量改后缀)
功能:将当前目录下的BAT和CMD格式批处理文件,批量转换成TXT格式。
用途:适用于需要将批处理文件转换后放在手机上看TXT电子书,因为文件数量多了手动改比较麻烦,想到用P处理,这是代码:
@echo off
title bat2txt
echo 将当前目录下的BAT文件的后缀都改成TXT
for /f "delims=" %%i in ('dir/b/l/a-d^|findstr ".cmd$"^&dir/b/a-d^|findstr/i ".bat$"') do (
if not "%%~nxi"=="%~nx0" ren "%%~nxi" "%%~ni.txt",2>nul || echo 忽略了对“%%i”的操作,此目录下存在“%%~ni.txt”)
pause
上述代码不简洁,请各位给出更优的方案,尽量代码简洁而且人性化,最好能添加一个转换以后可以恢复成原状的功能,当然再如果有备份的功能更好,希望有高手可以添加一些个性化的功能比如加个进度条并显示进度并显示处理细节,使之更人性化,谢谢!因本人DOS很浅薄,解决小问题都感觉困难。谢谢了。
Last edited by Batain on 2008-5-17 at 02:25 PM ]
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:
@echo off
title bat2txt
echo Renaming all BAT files in the current directory to TXT
for /f "delims=" %%i in ('dir /b /l /a-d ^| findstr ".cmd$" ^& dir /b /a-d ^| findstr /i ".bat$"') do (
if not "%%~nxi"=="%~nx0" (
ren "%%~nxi" "%%~ni.txt" 2>nul || echo Ignored the operation on "%%i", there is "%%~ni.txt" in this directory
)
)
pause
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 ]
|

拙拙的跟各位学习学习,增长学问。 |
|
2008-5-16 19:41 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
ren *.cmd *.txt
ren *.bat *.txt
ren *.cmd *.txt
ren *.bat *.txt
|
|
2008-5-16 19:52 |
|
|
gahoo
初级用户
 
积分 45
发帖 19
注册 2007-3-8
状态 离线
|
|
2008-5-16 19:55 |
|
|
gahoo
初级用户
 
积分 45
发帖 19
注册 2007-3-8
状态 离线
|
|
2008-5-16 19:55 |
|
|
Batain
初级用户
 
积分 24
发帖 11
注册 2008-2-1
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
不好意思,我问题没说清楚,我的意思是需要解决bat2txt的更优化的代码,因为我发这个帖子不是为了仅实现转换,而是为了寻求一些更优化,个性的解决方案,第2,3楼朋友的方法不适用于写成批文件,因为会连自身的后缀都改掉,改不掉的文件还要说明一下原因,不然会造成误会。我希望你们给出功能透明,操作人性化的批文件代码,让大家学习学习。随便什么时候回复,我们都愿意等高手们的方案,但不要仓促地提供不完善的方法。谢谢。
Last edited by Batain on 2008-5-17 at 02:38 PM ]
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 ]
|

拙拙的跟各位学习学习,增长学问。 |
|
2008-5-17 14:30 |
|
|
Batain
初级用户
 
积分 24
发帖 11
注册 2008-2-1
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
我看不懂四楼的朋友是什么意思,CN-DOS论坛不是罐水论坛,我们相信大家都会认真看每一个回贴的,并不是只看第一页的回贴,但愿你不要对大家怀有戒备之心。相信我们。你的回答精彩的话我们会收藏的,并且我们会记住你。毕竟这是我在此论坛贴的第一篇帖子,如果没有回帖的话我也很高兴,但是我讨厌看到不负责的回帖。<img src="images/smilies/face-laugh.png" align="absmiddle" border="0">
Last edited by Batain on 2008-5-17 at 02:45 PM ]
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 ]
|

拙拙的跟各位学习学习,增长学问。 |
|
2008-5-17 14:43 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 7 楼』:
5楼
使用 LLM 解释/回答一下
不是别人的方法不完善,而是你的问题没有描述清楚。
@echo off
for /f "tokens=1* delims=" %%a in ('dir /b *.bat *.cmd') do (
if "%%a" neq "%0" (
ren %%a %%~na.txt
)
)
It's not that someone else's method is imperfect, but that your problem isn't clearly described.
@echo off
for /f "tokens=1* delims=" %%a in ('dir /b *.bat *.cmd') do (
if "%%a" neq "%0" (
ren %%a %%~na.txt
)
)
|

 |
|
2008-5-17 14:46 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 8 楼』:
6楼
使用 LLM 解释/回答一下
4楼的朋友是说他想到的方法被2楼抢先一步贴出来了,没有其它意思,楼主不必介意。祝楼主在本论坛学习顺利。
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.
|

 |
|
2008-5-17 14:49 |
|
|
fengzi
中级用户
   金牌会员
积分 315
发帖 152
注册 2007-1-25
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
楼上的来自重庆?
我是沙平坝的``呵呵``
Are you from Chongqing, upstairs?
I'm from Shapingba, heh heh
|
|
2008-5-17 15:47 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
干嘛放到同一目录……放到父目录
bat里加上路径就可以了
这样简单……
或者…直接注册新的类型…
Last edited by slore on 2008-5-17 at 04:08 PM ]
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 ]
|
|
2008-5-17 16:02 |
|
|
Batain
初级用户
 
积分 24
发帖 11
注册 2008-2-1
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
谢谢你们的真诚!也谢谢7楼那位朋友的方法,同样是dir命令,你用得很简洁灵活,如果后缀名有好多种,可以很方便地添加。另外请问大家刷新文件夹的命令是什么?如果需要改后缀的文件成百上千之多,最好先改一部分再自动刷新一下文件夹然后再改,机器配置低的朋友就不会感觉卡了。。呵呵,谢谢你们!
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!
|

拙拙的跟各位学习学习,增长学问。 |
|
2008-5-18 12:34 |
|
|
moniuming
银牌会员
     永远的菜鸟
积分 1335
发帖 574
注册 2007-11-27 来自 广西
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
利用PING来暂停一下,每10个暂停几秒<img src="images/smilies/face-laugh.png" align="absmiddle" border="0">
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1* delims=" %%a in ('dir /b *.bat *.cmd') do (
if "%%a" neq "%0" (
ren %%a %%~na.txt
set /a n+=1
if "!n:~-1!"=="0" ping -n 5 127.1>nul
)
)
Use PING to pause. Pause for a few seconds every 10 times:)
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1* delims=" %%a in ('dir /b *.bat *.cmd') do (
if "%%a" neq "%0" (
ren %%a %%~na.txt
set /a n+=1
if "!n:~-1!"=="0" ping -n 5 127.1>nul
)
)
|
|
2008-5-18 14:20 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
我一次性改过几千个文件,没发现卡,我觉得这样分批修改反而会影响执行效率。
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.
(注:原句中“反而”不需要翻译,直接保留英文形式即可,整体按照要求翻译)
|

 |
|
2008-5-18 15:54 |
|
|
Batain
初级用户
 
积分 24
发帖 11
注册 2008-2-1
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
呵呵!谢谢你们,12楼的方法很好用,但是我不懂原理,我还不会变量扩展延时,有时间会慢慢去找资料看;还有我发现你们贴出的代码式样都很美观,缩进对齐得很有层次。是用的什么编辑器?还是手动空格或者TAB缩进的?
最近有点忙没时间放在学习上,上网也只是来论坛看一下回复,楼上几位四川重庆的朋友你们家里都平安吧?这次地震听说四川那边的豆腐渣房子太多,现在很多建筑商都会偷工减料的,真没办法。
Last edited by Batain on 2008-5-19 at 02:06 PM ]
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 ]
|

拙拙的跟各位学习学习,增长学问。 |
|
2008-5-19 14:04 |
|
|
gahoo
初级用户
 
积分 45
发帖 19
注册 2007-3-8
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
差点被楼主打击积极性了……
我再来一个
if "%1" equ "" exit
cd %1
ren *.cmd *.txt
ren *.bat *.txt
保存成批处理,然后把要批量改名的批处理所在文件夹拖放到这个批处理上,这样就解决自己也被改成txt的问题
注意,路径中不能包含有空格
感觉用for效率还是低了……所以还是直接ren好点
Last edited by gahoo on 2008-5-19 at 05:17 PM ]
Almost discouraged by the LZ...
I'll do another one
if "%1" equ "" exit
cd %1
ren *.cmd *.txt
ren *.bat *.txt
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 ]
|
|
2008-5-19 17:04 |
|