批量重命名 windows 中的多个文件?
batch rename multiple files in windows?
我想知道我的编码有什么问题,因为它不起作用
我想重命名 Chris 中的所有 png 文件。
但是失败了
for /f in ('C:/Users/Chris/Downloads/images/*.png')
do ren "C:\Users\Chris\Downloads\images\*.png" "%date:~10,4%-%date:~4,2%-%date:~7,2%_%HR%%time:~3,2%-img.png"
参数中不需要 /f,不需要引号,但您缺少变量声明
变量应该在 do-part 中使用,否则 for 没有多大帮助
for 将枚举完整路径,因此您需要使用 ~n
去除文件名
do 部分必须直接在 for 语句后面或者需要在圆括号内
完整代码如下:
for %%i in (C:/Users/Chris/Downloads/images/*.png) do (
ren "%%i" "%date:~10,4%-%date:~4,2%-%date:~7,2%_%HR%%time:~3,2%-%%~niimg.png"
)
如果为了使用for
循环,你需要指定一个变量来使用(即使你根本不在循环中使用变量),否则你会得到一个语法错误.虽然变量只能是一个字母,但这几乎是批处理中唯一一次变量区分大小写,所以你有 52 个字母,加上一些我见过的其他字符,比如 #。此外,do
必须 始终 与 )
.
在同一行
for /F
循环可以处理字符串、文本文件和其他批处理命令。
- 要处理字符串,请使用双引号:
for /F %%A in ("hello world") do echo %%A
- 要处理批处理命令,请使用单引号:
for /F %%A in ('dir /b') do echo %%A
- 要处理文本文件,根本不要使用任何引号:
for /F %%A in (C:\Users\Chris\image_list.txt) do echo %%A
您可能还想进入您正在处理的目录以简化操作。
pushd C:\Users\Chris\Downloads\images
for /F %%A in ('dir /b *.png') do (
REM I'm not sure what the %HR% variable is supposed to be, so I'm ignoring it.
ren "%%A" "%date:~10,4%-%date:~4,2%-%date:~7,2%_%HR%%time:~3,2%-img.png"
)
我想知道我的编码有什么问题,因为它不起作用
我想重命名 Chris 中的所有 png 文件。
但是失败了
for /f in ('C:/Users/Chris/Downloads/images/*.png')
do ren "C:\Users\Chris\Downloads\images\*.png" "%date:~10,4%-%date:~4,2%-%date:~7,2%_%HR%%time:~3,2%-img.png"
参数中不需要 /f,不需要引号,但您缺少变量声明
变量应该在 do-part 中使用,否则 for 没有多大帮助
for 将枚举完整路径,因此您需要使用 ~n
去除文件名do 部分必须直接在 for 语句后面或者需要在圆括号内
完整代码如下:
for %%i in (C:/Users/Chris/Downloads/images/*.png) do (
ren "%%i" "%date:~10,4%-%date:~4,2%-%date:~7,2%_%HR%%time:~3,2%-%%~niimg.png"
)
如果为了使用for
循环,你需要指定一个变量来使用(即使你根本不在循环中使用变量),否则你会得到一个语法错误.虽然变量只能是一个字母,但这几乎是批处理中唯一一次变量区分大小写,所以你有 52 个字母,加上一些我见过的其他字符,比如 #。此外,do
必须 始终 与 )
.
for /F
循环可以处理字符串、文本文件和其他批处理命令。
- 要处理字符串,请使用双引号:
for /F %%A in ("hello world") do echo %%A
- 要处理批处理命令,请使用单引号:
for /F %%A in ('dir /b') do echo %%A
- 要处理文本文件,根本不要使用任何引号:
for /F %%A in (C:\Users\Chris\image_list.txt) do echo %%A
您可能还想进入您正在处理的目录以简化操作。
pushd C:\Users\Chris\Downloads\images
for /F %%A in ('dir /b *.png') do (
REM I'm not sure what the %HR% variable is supposed to be, so I'm ignoring it.
ren "%%A" "%date:~10,4%-%date:~4,2%-%date:~7,2%_%HR%%time:~3,2%-img.png"
)