|
zzhh612
中级用户
  
积分 278
发帖 103
注册 2006-10-21
状态 离线
|
『楼 主』:
如何为多个子目录中的txt批量改文件扩展名.
使用 LLM 解释/回答一下
在一个目录下的若干个子目录中有许多以文本方式保存的C代码.
我怎样才能用一个批处理将这些以TXT为扩展名的代码文档变成以.C为扩展名的C源文件.
Last edited by zzhh612 on 2007-3-31 at 01:48 AM ]
There are many C codes saved in text form in several subdirectories under a directory. How can I use a batch to change these code documents with the TXT extension into C source files with the.C extension?
Last edited by zzhh612 on 2007-3-31 at 01:48 AM ]
|
|
2007-3-30 13:04 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
|
2007-3-30 13:14 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
@echo off
dir /b /a *.txt>1.txt
for /f "tokens=1,2 delims=. " %%i in (1.txt) do ren %%i.txt %%i.c
@echo off
dir /b /a *.txt>1.txt
for /f "tokens=1,2 delims=. " %%i in (1.txt) do ren %%i.txt %%i.c
|
|
2007-3-30 13:16 |
|
|
MagiCube
新手上路

积分 4
发帖 2
注册 2007-3-30
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
在XP下面,用命令ren *.txt *.c就可以把当前目录下所有.txt文件重命名为.c文件啦
初来乍到,看到这里很多高手,很多复杂的语法还不懂,像这个应该没有必要用复杂的方法吧
Under XP, you can use the command `ren *.txt *.c` to rename all `.txt` files in the current directory to `.c` files. Just arrived, seeing many experts here, and many complex grammars are not understood. Like this one, there should be no need to use complex methods.
|
|
2007-3-30 13:31 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
|
2007-3-30 13:32 |
|
|
zzhh612
中级用户
  
积分 278
发帖 103
注册 2006-10-21
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
不知flyinspace
试过了没有.目录列表应用dir /b /s才对.这样可以把文件名写入1.txt,但在执行重命名文件时,会提示找不到文件的路径.兄弟的代码怕是需要改进吧.也许思路是对的.
我想用批处理解决的原因是文本存在于多个不同级数的子目录下,单用命令REN来做很是麻烦的,当然WINDOWS下有批量改名的软件,我是想在实践中学一学批处理.不能总只靠一种方法来解决问题吧.
Last edited by zzhh612 on 2007-3-30 at 01:51 PM ]
I wonder if flyinspace has tried it. The directory listing should be correct with dir /b /s. This can write the file names into 1.txt, but when executing the file renaming, it will prompt that the path to the file is not found. Brother's code probably needs to be improved. Maybe the idea is correct.
The reason I want to use batch processing is that the text exists in multiple subdirectories of different levels. It is very troublesome to use the REN command alone. Of course, there are batch renaming software under WINDOWS. I want to learn batch processing in practice. I can't always rely on one method to solve the problem.
Last edited by zzhh612 on 2007-3-30 at 01:51 PM ]
|
|
2007-3-30 13:43 |
|
|
MagiCube
新手上路

积分 4
发帖 2
注册 2007-3-30
状态 离线
|
|
2007-3-30 14:00 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
呵,都说过了呀。
没有注意的。。。
忘记加几个参数了。
还有那个名字可以随便写的。
不一定是.txt
随便写个。fly也行啊。
Hehaha, I already said that.
I didn't pay attention...
I forgot to add a few parameters.
Also, that name can be written randomly.
It doesn't have to be .txt
You can just write something like .fly.
|
|
2007-3-30 14:08 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
试过了没有.目录列表应用dir /b /s才对.这样可以把文件名写入1.txt,但在执行重命名文件时,会提示找不到文件的路径.兄弟的代码怕是需要改进吧.也许思路是对的.
??
不是吧?
这个dir /b /s是可以随便写的。。
写dir /s /b都一样。。
Have you tried it or not. The directory listing application should be dir /b /s. This can write the file name into 1.txt, but when performing the file renaming, it will prompt that the path of the file is not found. Brother's code may need to be improved. Maybe the idea is correct.
??
No way?
This dir /b /s can be written casually.
Writing dir /s /b is the same.
|
|
2007-3-30 14:10 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
噢。开始你的要求里面没有子目录的。
就没有加上 /s参数。
Oh. The initial requirements didn't include subdirectories. So there was no addition of the /s parameter.
|
|
2007-3-30 14:13 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
@echo off
dir /b /a /s *.txt>1.bpx
for /f "tokens=1,2 delims=. " %%i in (1.bpx) do ren %%i.txt %%i.c
加/a参数是为了防止有隐藏文件的出现。
@echo off
dir /b /a /s *.txt>1.bpx
for /f "tokens=1,2 delims=. " %%i in (1.bpx) do ren %%i.txt %%i.c
Adding the /a parameter is to prevent the appearance of hidden files.
|
|
2007-3-30 14:15 |
|
|
zzhh612
中级用户
  
积分 278
发帖 103
注册 2006-10-21
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
flyinspace的代码在执行时仍会提示系统找不到文件.
没有能改名,只有根目录下的被改了,
我自己得来的,试过了还行
@echo off
FOR /R c:\test %%a IN (*.txt) DO (ren %%a %%~na.c)
pause
只是文件名不能有逗号,当然这本来也不规范,所以也没有想法来包括它了,如果非要包括进来,也只有高手来解决了..
Last edited by zzhh612 on 2007-3-30 at 02:57 PM ]
The code of flyinspace still prompts that the system cannot find the file when executing.
There is no way to rename, only the one in the root directory is renamed.
I got it by myself, and it worked after testing.
@echo off
FOR /R c:\test %%a IN (*.txt) DO (ren %%a %%~na.c)
pause
Just that the file name cannot have commas. Of course, this is not standard originally, so there is no idea to include it. If it must be included, only experts can solve it..
Last edited by zzhh612 on 2007-3-30 at 02:57 PM ]
|
|
2007-3-30 14:48 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
哦。我自己试过了啊?
所有的目录下的文件都可以更改?
要想最规范的话。还要加上不少判断的语句。
但你想要麻烦么?
Oh. I tried it myself?
Can all the files in all directories be changed?
To be the most standardized, a lot of judgment statements need to be added.
But do you want to be troublesome?
|
|
2007-3-30 15:06 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
flyinspace的作息时间怎么黑白颠倒啊????
Why does flyinspace's work and rest schedule have reversed day and night?
|
|
2007-3-30 21:18 |
|
|
zzhh612
中级用户
  
积分 278
发帖 103
注册 2006-10-21
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
flyinspace的代码在执行时仍会提示系统找不到文件.
所有子目录下的TXT文件一个也没有改.
不知你是怎样运行成功的.
The code of flyinspace still prompts that the system cannot find the file when executed.
None of the TXT files in all subdirectories have been changed.
I don't know how you ran it successfully.
|
|
2007-3-31 01:39 |
|