|
fanglor
初级用户
 
积分 68
发帖 30
注册 2007-1-16
状态 离线
|
『楼 主』:
如何把同一目录下同一类型的文件名改成连续的数字名?
使用 LLM 解释/回答一下
刚才看到一位兄弟求救用批处理改文件名,就想起了我很久以前的一个想法。
比如说在一个目录下有N个JPG文件,怎么把它改成1.JPG,2.JPG,3.JPG等等.
我试了好多次都没有成功.希望哪位好心的高手能帮着解决一下.代码最好附上注
释.本人能力有限,怕看不懂.谢谢啦.
Just now I saw a brother asking for help to change file names with batch processing, and it reminded me of an idea I had a long time ago.
For example, there are N JPG files in a directory, how to change them to 1.JPG, 2.JPG, 3.JPG and so on.
I have tried many times without success. I hope some kind expert can help solve it. It's best to attach comments to the code. I have limited ability and may not understand it. Thank you.
|
|
2007-4-13 14:17 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
试试这个看满足要求么
- @echo off
- set count=1
- for /f "delims=" %%a in ('dir /b *.jpg') do ren %%a %count%.jpg && set /a count+=1
BJSH发表于: 2007-04-13 08:07
Last edited by bjsh on 2007-4-13 at 09:17 AM ]
Let's try this to see if it meets the requirements
- @echo off
- set count=1
- for /f "delims=" %%a in ('dir /b *.jpg') do ren %%a %count%.jpg && set /a count+=1
BJSH posted on: 2007-04-13 08:07
Last edited by bjsh on 2007-4-13 at 09:17 AM ]
|
|
2007-4-13 21:18 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
@echo off
set num=0
for /f "delims=" %%i in ('dir/b *.jpg') do set/a num+=1&call :re "%%i"
goto :eof
:re
ren %1 %num%.jpg
```@echo off
set num=0
for /f "delims=" %%i in ('dir/b *.jpg') do set/a num+=1&call :re "%%i"
goto :eof
:re
ren %1 %num%.jpg
```
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-4-13 21:55 |
|
|
htysm
高级用户
   
积分 866
发帖 415
注册 2005-12-4
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
这个需要批处理吗?手工来的更快吧。
编辑》全选》重命名》输入1.jpg。回车即可。
Does this require a batch process? Manual work is faster. Edit > Select All > Rename > Enter 1.jpg. Press Enter.
|
|
2007-4-13 23:09 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by htysm at 2007-4-13 10:09:
这个需要批处理吗?手工来的更快吧。
编辑》全选》重命名》输入1.jpg。回车即可。
可惜出来的除了第一个是1.jpg,其它的是1 (n).jpg(XP SP2)
Originally posted by htysm at 2007-4-13 10:09:
Does this require a batch processing? Doing it manually is faster.
Edit > Select All > Rename > Enter 1.jpg. Press Enter.
Unfortunately, the first one is 1.jpg, and the others are 1 (n).jpg (XP SP2)
|
|
2007-4-13 23:29 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
我的win2000不能实现htysm兄说的
My Windows 2000 can't achieve what Brother htysm said
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-4-14 00:03 |
|
|
fanglor
初级用户
 
积分 68
发帖 30
注册 2007-1-16
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
谢谢各位兄弟的帮忙!
经测试:二楼的方法好像存在一点问题。错误提示:存在一个重命名文件或是找不到文件。结果:只能改一个成1.JPG!
三楼的可以.呵呵......没想到困扰我这么多年的问题今天终于搞定了.
Thanks to the help of all brothers!
After testing: The method on the second floor seems to have a problem. Error message: There is a renamed file or the file is not found. Result: Only one can be changed to 1.JPG!
The third floor is okay. Hehe... I didn't expect that the problem that has troubled me for many years was finally solved today.
|
|
2007-4-14 03:59 |
|
|
bjsh
银牌会员
    
积分 2000
发帖 621
注册 2007-1-1
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
是的;我的那个应该启用变量延迟;修正后如下
- @echo off & setlocal enabledelayedexpansion
- set count=1
- for /f "delims=" %%a in ('dir /b *.jpg') do ren "%%a" "!count!.jpg" && set /a count+=1
BJSH发表于: 2007-04-13 15:15
Yes; mine should enable variable delay; after correction it is as follows
- @echo off & setlocal enabledelayedexpansion
- set count=1
- for /f "delims=" %%a in ('dir /b *.jpg') do ren "%%a" "!count!.jpg" && set /a count+=1
BJSH posted on: 2007-04-13 15:15
|
|
2007-4-14 04:26 |
|
|
fanglor
初级用户
 
积分 68
发帖 30
注册 2007-1-16
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
for /f "delims=" %%a in ('dir /b *.jpg') do ren "%%a" "!count!.jpg" && set /a count+=1
"delims="这个是什么意思啊?
"!count!.jpg"这一句能调用后面的count 吗?
能不能解释一下啊?谢谢了!还是看不太懂!
### 关于 `for /f "delims=" %%a in ('dir /b *.jpg') do ren "%%a" "!count!.jpg" && set /a count+=1"` 的问题解释
#### 1. 关于 `"delims="` 的意思
在 `for /f` 循环中,`delims` 是用于指定分隔符的参数。默认情况下,`for /f` 会以空格、制表符等作为默认的分隔符来分割每行文本。而 `delims=` 表示将分隔符设置为空,这样就会按整行来处理,不会对每行进行分割,而是将每行作为一个整体赋值给循环变量 `%%a`。
#### 2. 关于 `"!count!.jpg"` 能否调用后面的 `count`
这里使用了延迟环境变量扩展。在批处理中,普通的变量 `%count%` 在循环内部如果没有开启延迟扩展的话,获取的是循环初始时的 `count` 值,而使用 `!count!` 并且开启了延迟环境变量扩展(一般通过 `setlocal enabledelayedexpansion` 来开启),就可以在循环过程中获取到 `count` 实时变化后的值,所以这里 `!count!.jpg` 能够调用到后面实时更新的 `count` 值。
不过你提供的内容中前面应该还有开启延迟环境变量扩展的相关代码,比如通常会有 `@echo off` 之后跟着 `setlocal enabledelayedexpansion` 之类的代码来支持延迟环境变量扩展,否则单独这一句可能无法正常获取到实时更新的 `count` 值。
|
|
2007-4-15 03:20 |
|
|
kich
中级用户
  
积分 397
发帖 168
注册 2006-10-8
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
没必要用批处理!!
ACDsee 9 (软件)可以支持批量重命名!!
只过是你研究技术,你看他们说的吧,如果只是批量改文件名,那就可以用这个软件,非常适合数码相机照出来的相片改名!!
No need to use batch processing!!
ACDsee 9 (software) can support batch renaming!!
It's just that you are researching technology, you can look at what they say. If it's just batch renaming file names, then you can use this software, which is very suitable for renaming photos taken by digital cameras!!
|
|
2007-4-15 04:12 |
|
|
Waterlive
初级用户
 
积分 52
发帖 21
注册 2007-2-9
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
4搂9搂的兄台,我们来这里是为了学习批处理,使用其他工具来达到同样效果就违背了学习的目的
这几天我一直在琢磨怎么写个批量改名……有启发了!
Fellow friends on the 4th and 9th floors, we come here to learn batch processing, and using other tools to achieve the same effect goes against the purpose of learning.
I've been thinking about how to write a batch rename these days... Got inspired!
|
|
2007-5-28 13:28 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
一句:
@echo off
for /f "delims=" %%a in ('dir /b *.jpg') do set /a count+=1&&call ren "%%a" "%%count%%.jpg"
```
@echo off
for /f "delims=" %%a in ('dir /b *.jpg') do set /a count+=1&&call ren "%%a" "%%count%%.jpg"
```
|
|
2007-5-28 13:45 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
进一步“简化”:
@echo off
for %%a in (*.jpg) do set /a count+=1&&call ren "%%a" "%%count%%.jpg"
Further "simplify":
@echo off
for %%a in (*.jpg) do set /a count+=1&&call ren "%%a" "%%count%%.jpg"
|
|
2007-5-28 14:11 |
|
|
qq82015930
中级用户
  
积分 235
发帖 109
注册 2006-8-24
状态 离线
|
|
2007-5-28 21:19 |
|
|
liu3157551
中级用户
  
积分 259
发帖 164
注册 2006-9-21
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
好东西呀,收录了^_^ 2007年[9月3日9:44:54]星期一
Good stuff, included ^_^ Monday, September 3, 2007 9:44:54
|
|
2007-9-3 09:54 |
|