简体   繁体   English

是否可以将目录中的所有文件重命名为0.jpg,1.jpg,2.jpg等?

[英]Is it possible rename all files in a directory to 0.jpg, 1.jpg, 2.jpg, etc?

I have a bunch of images (100+) in a directory, all with different names. 我的目录中有一堆图像(超过100张),它们的名称都不同。 Is there any way to rename them, possibly with a script (I'm running Windows), to 0.jpg, 1.jpg, 2.jpg, etc... without having to rename each one individually? 有什么方法可以将它们重命名为0.jpg,1.jpg,2.jpg等,而可能需要使用脚本(我正在运行Windows)将它们重命名为0.jpg,1.jpg,2.jpg等吗? I could launch a Linux virtual machine and copy them over if it isn't possible in Windows. 如果无法在Windows中启动,我可以启动Linux虚拟机并将其复制。

I've got this so far 到目前为止我已经知道了

@echo off
setlocal enableDelayedExpansion
set MYDIR=F:\Pictures\Wallpapers
set /a count = 0
for /F %%x in ('dir /B/D %MYDIR%') do (
  echo %%x
  @echo !count!
  set /a count+=1
)

Which display the correct file name and the correct counter, but when I try 其中显示正确的文件名和正确的计数器,但是当我尝试

ren %%x !count!.jpg

Tells me "The system could not find the file specified." 告诉我“系统找不到指定的文件。”

You are not providing the full path for the source file. 您没有提供源文件的完整路径。 Don't forget that %%x is just the file name; 不要忘了%%x只是文件名。 you need to prepend %MYDIR% to have a complete path: 您需要在%MYDIR%前面加上完整的路径:

ren %MYDIR%\%%x !count!.jpg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM