2

I have several hundreds .jpg Images. The problem is, that some have ".jpg" and others have ".JPG" as the file-extension.

I'm on Windows 7, 64 bit. How can I easily change all file-extensions to the same name (".jpg" in this case)? Is there some kind of commandline-command?

3 Answers 3

4

from a command prompt in the directory: ren *.* *.jpg

1
  • Or to be more specific: ren *.jpg *.jpg Jan 18, 2011 at 0:33
1

To do it recursively:

for /r %f in (*.jpg) do rename "%f" "%~nf.jpg"

or

for /r %f in (*.jpg) do rename "%f" "*.jpg"
1

A powershell way:

get-childitem | where {$_.name -match 'JPG'} | %{rename-item -path $_ -newname "$($_.basename).jpg"}

Edit: Requested explanation

The get-childitem is much like the old 'dir' command.

where is actually an alias for where-object and is a filtering cmdlet

The percent sign (%) is an alias for the cmdlet foreach-object, which performs a for loop for each item that it is passed.

rename-item is pretty self explanatory. :)

The $_ you see is a special symbol for "THIS." "THIS" is whatever object it is working on at the time.

So in plain English:

"Get the files in the current folder that contain 'JPG.' For each of those, rename them with the original base name, and add '.jpg' to the end."

update: Stumbled across THIS on stackoverflow. Looks like it would fit the bill.

3
  • Can you explain what this command does in some detail?
    – Zypher
    Jan 18, 2011 at 2:55
  • Updated just for you, Zypher :D Jan 18, 2011 at 6:15
  • ooh fail... I just tried it and powershell doesn't understand caps!? hrmm. Jan 18, 2011 at 6:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .