开发者

copy and rename files of a certain extension via batch file

开发者 https://www.devze.com 2023-01-26 21:01 出处:网络
I have a folder that has a bunch of files such image_hello.png, helloworld.png, wired.png. I woul开发者_StackOverflowd like to copy these files and then rename them as 1.png, 2.png, 3.png via script o

I have a folder that has a bunch of files such image_hello.png, helloworld.png, wired.png. I woul开发者_StackOverflowd like to copy these files and then rename them as 1.png, 2.png, 3.png via script or batch file

I am not sure what the best way to start this is, i can copy over the files easily, but after that, i am not sure how to rename them based on the extension.

Any ideas?


Something like this:

@echo off
SET count=1
FOR /f "tokens=*" %%G IN ('dir /b *.png') DO (call :rename_next "%%G")
GOTO :eof

:rename_next
ren "%1" %count%.png
set /a count+=1
GOTO :eof


Take a look here:

  • http://www.computing.net/answers/windows-xp/batch-file-to-renumber-files-in-folders/181900.html

Something along these lines should work (note: don't have Windows to test):

set n=1
for %%i in (*.png) do (
  call ren %%i %%n%%.pn_
  set /a n=n+1)
ren *.pn_ *.png

Note that if you only want to do it once, you can use Explorer, as per here:

  • http://www.mediacollege.com/computer/file/batch-rename/windows-xp.html

or some other utilities, like the one mentioned in the first link:

  • http://www.snapfiles.com/get/bfrenamer.html
0

精彩评论

暂无评论...
验证码 换一张
取 消