Domanda

can somebody help me with code.... i have main folder named as "book" inside it 500 sub folders as following

book/page1/Image/image 2.jpg
book/page2/Image/image 2.jpg
book/page3/Image/image 2.jpg
book/page4/Image/image 2.jpg
book/page5/Image/image 2.jpg
.
.
.

i want the images to be renamed as:

book/page1/Image/1.jpg
book/page2/Image/2.jpg
book/page3/Image/3.jpg
book/page4/Image/4.jpg
book/page5/Image/5.jpg
.
.
.

help please

È stato utile?

Soluzione 2

The Batch file below renames the files to the folder names, removing the page part:

@echo off
setlocal EnableDelayedExpansion

cd \book
for /D %%a in (*) do (
   set folder=%%a
   ren "%%a\Image\image 2.jpg" "!folder:page=!.jpg"
)

The Batch file below renames the files to a sequential two-digits number, disregarding the folder names:

@echo off
setlocal EnableDelayedExpansion

cd \book
set number=100
for /D %%a in (*) do (
   set /A number+=1
   ren "%%a\Image\image 2.jpg" "!number:~1!.jpg"
)

If you want the numbers have just one digit, change the number assignment by this one: set number=10.

Altri suggerimenti

@ECHO OFF
SETLOCAL
FOR /f "tokens=1*delims=[]" %%i IN (
 'dir /s /b /a-d "u:\book\image 2.jpg"^|find /n /v ""'
) DO ECHO REN "%%j" image%%i.jpg

This should report the renames required.

Remove the ECHO keyword from the last line to actually perform the rename - after checking.

Put this in a bat file in the book folder. Of course you should make a copy of the entire book folder before trying anything like this.

@echo off
for /f "delims=page" %%a in ('DIR /ad /b') do rename "page%%a\Image\Image2.jpg" "%%a.jpg"
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top