简体   繁体   中英

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. 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? I could launch a Linux virtual machine and copy them over if it isn't possible in Windows.

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; you need to prepend %MYDIR% to have a complete path:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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