'Changing all files' extensions in a folder with one command on Windows
How can I use the Windows command line to change the extensions of thousands of files to *****.jpg
?
Solution 1:[1]
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
Solution 2:[2]
on CMD
type
ren *.* *.jpg
. will select all files, and rename to * (what ever name they have) plus extension to jpg
Solution 3:[3]
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
Solution 4:[4]
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.
Solution 5:[5]
thats simple
ren *.* *.jpg
try this in command prompt
Solution 6:[6]
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.
Solution 7:[7]
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.
Solution 8:[8]
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.
Solution 9:[9]
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/
Solution 10:[10]
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.
Solution 11:[11]
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
Solution 12:[12]
An alternative way to rename files using the renamer npm package.
below is an example of renaming files extensions
renamer -d --path-element ext --find ts --replace js *
Solution 13:[13]
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")}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow