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")}
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 *
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.
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.
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.
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.
on CMD
type
ren *.* *.jpg
. will select all files, and rename to * (what ever name they have) plus extension to jpg
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
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/
thats simple
ren *.* *.jpg
try this in command prompt
Source: Stackoverflow.com