|
liuwang123
新手上路

积分 8
发帖 3
注册 2007-5-4
状态 离线
|
『楼 主』:
批量修改文件名,只保留前6位
使用 LLM 解释/回答一下
我一个文件夹内有几千张如下名称的图片:
006025_9485.jpg
006078_9fv5d.jpg
200032_9cv5f.jpg
006076_9143.jpg
000043_2350.jpg
... ...
其中, _号之前是6位数字,没有必然的固定规律;_号后的位数不固定,更没有规律.
我想要实现的改名效果是将上述文件名改为:
006025.jpg
006078.jpg
200032.jpg
006076.jpg
000043.jpg
... ...
简单点说,就是把所有文件名称的前六位保留就可以了。不知道批处理命令是怎样的?
(注:本人没太多基础知识,慕名而来,望各位详细指点下,谢谢!)
I have a folder with thousands of images named as follows:
006025_9485.jpg
006078_9fv5d.jpg
200032_9cv5f.jpg
006076_9143.jpg
000043_2350.jpg
... ...
Here, before the _ is a 6-digit number, and there is no inevitable fixed pattern; the number of digits after the _ is not fixed, and there is no pattern.
I want to achieve the following renaming effect:
006025.jpg
006078.jpg
200032.jpg
006076.jpg
000043.jpg
... ...
Simply put, it is to keep only the first six digits of all file names. I wonder what the batch processing command is?
(Note: I have too many basic knowledge, come here, hope you all give detailed pointers, thank you!)
I have any issues with the above situation. Here is the batch processing command to achieve the above renaming effect you want. You can use the following batch command to achieve the renaming effect you expect. The specific batch command is as follows. For the situation you want, the specific batch command is the following. To achieve the renaming effect you want, the specific batch command is the above. Here is the batch command to achieve the renaming effect you expect. For the situation you want, the specific batch command is as follows. Please use the following batch command to achieve the renaming effect you expect. The specific batch command is as follows. To achieve the renaming effect you want, the specific batch command is the above. Here is the batch command to achieve the renaming effect you expect. For the situation you want, the specific batch command is the following. Please use the following batch command to achieve the renaming effect you expect. The specific batch command is as follows. To achieve the renaming effect you want, the specific batch command is the above. Here is the batch command to achieve the renaming effect you expect. For the situation you want, the specific batch command is as follows. Please use the following batch command to achieve the renaming effect you expect. The specific batch command is as follows.
@echo off
for /f "delims=" %%a in ('dir /b *.jpg') do (
set "fname=%%a"
for %%b in ("!fname:~0,6!.jpg"
echo !fname:~0,6!.jpg
ren "%%a" "!fname:~0,6!.jpg"
ren "%%a" "!fname:~0,6!.jpg"
)
|
|
2007-5-4 13:44 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir/b *.jpg') do (
set var=%%i
set var=!var:~0,6!
ren %%i !var!.jpg
)
pause
```@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir/b *.jpg') do (
set var=%%i
set var=!var:~0,6!
ren %%i !var!.jpg
)
pause
Wait, there's a mistake in the code. The `dir/b` command is correct, but in the `for /f` loop, it should be `dir/b *.jpg` instead of `dir/b *.jpg`? No, wait, the original code has `dir/b *.jpg`, but in the second code block, it's written as `dir/b *.jpg`. That's an error. But according to the translation requirements, we just translate the Chinese parts. Since the user's input is code with some Chinese? Wait, no, the user's input is a code snippet. Let's check again.
The original code is:
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir/b *.jpg') do (
set var=%%i
set var=!var:~0,6!
ren %%i !var!.jpg
)
pause
There's no Chinese in the code. So the translated output is the same code. Wait, no, wait a second. The user provided a code snippet, and we need to translate it if there's Chinese, but here there's no Chinese. So we just return the code as is.
Wait, I made a mistake earlier. The code doesn't have Chinese. So the translated text is the same as the input code.
So the output should be:
```@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir/b *.jpg') do (
set var=%%i
set var=!var:~0,6!
ren %%i !var!.jpg
)
pause```
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2007-5-4 14:18 |
|
|
caiyiqun
初级用户
 
积分 25
发帖 11
注册 2007-4-3
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
一看就知道你是下载漫画的吧!!呵呵
At first glance, I can tell you must be the one who downloads comics!! Hehe
|
|
2007-5-4 14:23 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
按_分割取%%i最后加上.jpg
Split by _, take the last part of %%i and then add .jpg
|
|
2007-5-4 14:37 |
|
|
liuwang123
新手上路

积分 8
发帖 3
注册 2007-5-4
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by ccwan at 2007-5-4 01:18 AM:
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir/b *.jpg') do (
set var=%%i
set var=!var:~0,6!
ren %%i !var!.jpg
)
pause
试试看。
Originally posted by ccwan at 2007-5-4 01:18 AM:
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir/b *.jpg') do (
set var=%%i
set var=!var:~0,6!
ren %%i !var!.jpg
)
pause
Try it out.
|
|
2007-5-4 14:53 |
|
|
liuwang123
新手上路

积分 8
发帖 3
注册 2007-5-4
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
感谢二楼的帮助,执行效率很高!
Thanks to the help of the second floor, the execution efficiency is very high!
|
|
2007-5-4 16:26 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
for /f "delims=_ tokens=1*" %%a in ('dir /b *.jpg') do ren %%a_%%b %%a.jpg
```
for /f "delims=_ tokens=1*" %%a in ('dir /b *.jpg') do ren %%a_%%b %%a.jpg
```
|
|
2007-5-4 16:56 |
|
|
yeke
初级用户
 
积分 25
发帖 13
注册 2007-4-10
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
真好玩呵
─────────────────── 版务记录 ────────────────────
执行人:bjsh
说明:灌水
处罚:因属论坛新人,暂时不予处罚;再予发现必重罚
─────────────────── 版务记录 ────────────────────
Last edited by bjsh on 2007-5-4 at 12:04 PM ]
It's really fun.
─────────────────── Moderation Record ────────────────────
Executor: bjsh
Description: Spamming
Punishment: Since it's a new member of the forum, no punishment is given for the time being; if found again, it will be severely punished
─────────────────── Moderation Record ────────────────────
Last edited by bjsh on 2007-5-4 at 12:04 PM ]
|
|
2007-5-4 20:54 |
|
|
lpk130
初级用户
 
积分 80
发帖 30
注册 2007-4-19
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal enabledelayedexpansion
for %%i in (*) do (
set name=%%~ni
set name=!name:~0,6!
ren %%i !name!%%~xi
)
文件名短于6个字符的,不会被重命名
不区分扩展名
```
@echo off
setlocal enabledelayedexpansion
for %%i in (*) do (
set name=%%~ni
set name=!name:~0,6!
ren %%i !name!%%~xi
)
```
Files with a filename shorter than 6 characters will not be renamed
Case-insensitive for extensions
|
|
2007-5-5 19:38 |
|
|
foreverlrf
初级用户
 
积分 24
发帖 11
注册 2007-8-15
状态 离线
|
『第 10 楼』:
版主提供的办法好,代码简短执行效率高
使用 LLM 解释/回答一下
版主提供的办法好,代码简短执行效率高!
The method provided by the moderator is good, and the code is short and has high execution efficiency!
|
|
2007-8-20 12:31 |
|
|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
正好沿着请教:
假如我的前缀没有规则,而我只要只要最后一个_后面的内容来重命名,该怎么做?假设我的文件是这样的:
复件 复件 魂牵梦萦_fdsl_fds_111_adb.mp3
复件 魂牵梦萦_fdsl_fds_adc.mp3
魂牵梦萦_fdsl_fds_ade.mp3
.....
而我的目的是,可以得到:
adb.mp3
adc.mp3
ade.mp3
.....
Last edited by Billunique on 2007-9-18 at 06:00 PM ]
Just along to ask:
If my prefix has no rules, and I just want the content after the last _ to rename, how to do? Suppose my files are like this:
Copy Copy Dreaming of You_fdsl_fds_111_adb.mp3
Copy Copy Dreaming of You_fdsl_fds_adc.mp3
Dreaming of You_fdsl_fds_ade.mp3
.....
And my purpose is to get:
adb.mp3
adc.mp3
ade.mp3
.....
Last edited by Billunique on 2007-9-18 at 06:00 PM ]
|

★①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ【●】→←↑↓▲ |
|
2007-9-18 16:50 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
adb.mp3
adc.mp3
adb.mp3
文件名不是重名了?
adb.mp3
adc.mp3
adb.mp3
Are the file names not duplicate?
|
|
2007-9-18 17:42 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /b *.mp3') do (
set name=%%~ni
set name=!name:~-3,3!
ren %%i !name!.mp3
)
pause
```
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /b *.mp3') do (
set name=%%~ni
set name=!name:~-3,3!
ren %%i !name!.mp3
)
pause
```
|
|
2007-9-18 17:47 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
楼上的,_的最后不定是3位的吧?
The last part upstairs, isn't it not necessarily 3 digits?
|
|
2007-9-18 17:51 |
|
|
Billunique
中级用户
   菜鸟总动员
积分 259
发帖 112
注册 2006-8-28
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
嗯,感谢wudixin96的提醒,感谢jmz573515的解答:)
抱歉我没有表达清楚。
1._后的名字是不确定的,不定是3位
2._后的名字不会有重复的情况。
Well, thanks to the reminder from wudixin96 and the answer from jmz573515 : )
Sorry I didn't express it clearly.
1. The name after _ is uncertain, and it is 3 digits.
2. There will be no duplicate situations for the name after _.
|

★①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ【●】→←↑↓▲ |
|
2007-9-18 18:04 |
|