How can I use the Windows command line to change the extensions of thousands of files to *****.jpg
?

- 9,283
- 4
- 29
- 38

- 7,026
- 18
- 68
- 102
-
what do you mean by changing all extensions as *****.jpg? does it means all files extensions to jpg? if yes use ren *.* *.jpg – Imran Rizvi Mar 27 '12 at 07:42
-
what operating system? How do you want to change them? – bryce Mar 27 '12 at 07:44
-
@bryce off course windows operating system.. – Berker Yüceer Mar 27 '12 at 07:55
15 Answers
You can use ren
(as in rename):
ren *.XXX *.YYY
And of course, switch XXX and YYY for the appropriate extensions. It will change from XXX to YYY. If you want to change all extensions, just use the wildcard again:
ren *.* *.YYY
One way to make this work recursively is with the FOR
command. It can be used with the /R
option to recursively apply a command to matching files. For example:
for /R %x in (*.txt) do ren "%x" *.renamed
will change all .txt
extensions to .renamed
recursively, starting in the current directory.
%x
is the variable that holds the matched file names.
And, since you have thousands of files, make sure to wait until the cursor starts blinking again indicating that it's done working.
Note: this works only on cmd. Won't work on Powershell or Bash

- 2,887
- 2
- 20
- 37

- 18,829
- 16
- 59
- 101
-
*.XXX will change files for that particular extension (means it will rename all files with extension XXX) – Habib Mar 27 '12 at 07:44
-
@keyser5053 also can i get a report about the action made here.. with using `ren *.* *.jpg > E:\Log\Cmd\ExtChange\ext.txt`? – Berker Yüceer Mar 27 '12 at 12:34
-
-
1
-
-
6I couldn't get this to work in powershell, but it worked fine in cmd.exe. Just so that others are aware. – hazzey Oct 01 '17 at 00:29
-
-
When doing a wildcard match, you need to include the match in the target filename: `ren "*.html" "#1.pug"` – Martinffx Jan 31 '23 at 08:17
on CMD
type
ren *.* *.jpg
. will select all files, and rename to * (what ever name they have) plus extension to jpg

- 219,104
- 29
- 407
- 436
Rename behavior is sometimes 'less than intuitive'; for example...
ren *.THM *.jpg will rename your THM files to have an extension of .jpg. eg: GEDC003.THM will be GEDC003.jpg
ren *.THM *b.jpg will rename your THM files to *.THMb.jpg. eg: GEDC004.THM will become GEDC004.THMb.jpg
ren *.THM *.b.jpg will rename your THM files to *.b.jpg eg: GEDC005.THM will become GEDC005.b.jpg

- 121
- 1
- 2
NOTE: not for Windows
Using ren-1.0 the correct form is:
"ren *.*" "#2.jpg"
From man ren
The replacement pattern is another filename with embedded wildcard indexes, each of which consists of the character # followed by a digit from 1 to 9. In the new name of a matching file, the wildcard indexes are replaced by the actual characters that matched the referenced wildcards in the original filename.
and
Note that the shell normally expands the wildcards * and ?, which in the case of ren is undesirable. Thus, in most cases it is necessary to enclose the search pattern in quotes.

- 26,542
- 16
- 152
- 170

- 1,334
- 17
- 18
-
-
1`man ren`? The question was about Windows/`cmd`. Do those now provide `man` pages? What is `ren-1.0` and how can we view its `man` page in context? – underscore_d Jun 21 '16 at 15:21
For my windows, ren
command wasn't working. So, I googled a little bit and wrote a universal solution in bash. You can try running it in on git bash
from windows and it also runs on linux shell.
for f in `find * -type f | grep .png`; do mv -- "$f" "${f%.png}.jpg"; done

- 315
- 4
- 8
Rename multiple file extensions:
You want to change ringtone1.mp3
, ringtone2.mp3
to ringtone1.wav
, ringtone2.wav
Here is how to do that: I am in d drive on command prompt (CMD) so I use:
d:\>ren *.* *.wav
This is just an example of file extensions, you can use any type of file extension like WAV, MP3, JPG, GIF, bmp, PDF, DOC, DOCX, TXT this depends on what your operating system.
And, since you have thousands of files, make sure to wait until the cursor starts blinking again indicating that it's done working.
Just for people looking to do this in batch files, this code is working:
FOR /R "C:\Users\jonathan\Desktop\test" %%f IN (*.jpg) DO REN "%%f" *.png
In this example all files with .jpg extensions in the C:\Users\jonathan\Desktop\test directory are changed to *.png.

- 31
- 1
I had the problem with a designer delivering images without extension (apple mac sometimes does it). So use can use
ren *. *.jpg
to add an extension, so that a windows user can use the files.

- 3,470
- 4
- 23
- 35
-
Thanks. Your answer was useful for me. I had to remove all the files extensions, but I didn't know that syntax with empty extension on right side of the dot. I executed `ren *.* *.` and it remove all the extensions. – august0490 Apr 25 '22 at 09:11
In my case I had a directory with 800+ files ending with .StoredProcedure.sql
(they were scripted with SSMS).
The solutions posted above didn't work. But I came up with this:
(Based on answers to batch programming - get relative path of file)
@echo off
setlocal enabledelayedexpansion
for %%f in (*) do (
set B=%%f
set B=!B:%CD%\=!
ren "!B!" "!B:.StoredProcedure=!"
)
The above script removes the substring .StoredProcedure
from the filename. I'm sure it can be adapted to cover more cases, ask for input and be overall more generic.

- 7,807
- 7
- 51
- 95
-
2replace your two `set` commands with this single one: `set "B=%%~nxf"`. (`%%~nxf` is **n**ame and e**x**tension of `%%f`). `%cd%` might be invalid, when you do it recursive. – Stephan Apr 16 '19 at 09:02
I know this is so old, but i've landed on it , and the provided answers didn't works for me on powershell so after searching found this solution
to do it in powershell
Get-ChildItem -Path C:\Demo -Filter *.txt | Rename-Item -NewName {[System.IO.Path]::ChangeExtension($_.Name, ".old")}
credit goes to http://powershell-guru.com/powershell-tip-108-bulk-rename-extensions-of-files/

- 342
- 1
- 2
- 11
What worked for me is this one(cd to the folder first):
Get-ChildItem -Filter *.old | Rename-Item -NewName {[System.IO.Path]::ChangeExtension($_.Name, ".new")}

- 89
- 10
You can try this to rename into *.jpg:
forfiles /S /M *.* /C "cmd /c rename @file @fname.jpg"

- 400
- 4
- 16