Keep Original File Name When Renaming File Extension

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
swfisher
Posts: 2
Joined: 22 May 2014 12:52

Keep Original File Name When Renaming File Extension

#1 Post by swfisher » 22 May 2014 12:58

I am trying to rename files in a directory from .ps5 format to .ps using a batch file. How can I rename the file and keep the original file name without having to manually putting the file name in the batch file. For example, if I put a file named 12345.ps5 into folder C:\RenameFile and run the batch file I would like the output file to be 12345.ps Are there some wildcards I could use to accomplish this?

-stephen

Compo
Posts: 488
Joined: 21 Mar 2014 08:50

Re: Keep Original File Name When Renaming File Extension

#2 Post by Compo » 22 May 2014 14:10

This should do you!

Code: Select all

REN C:\RenameFile\*.ps5 *.ps

aGerman
Expert
Posts: 3761
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Keep Original File Name When Renaming File Extension

#3 Post by aGerman » 22 May 2014 14:12

Or you could use a loop.

Code: Select all

for %%i in (*.ps5) do ECHO ren "%%i" "%%~ni.ps"

Remove the ECHO command if you're sure it would work.

Regards
aGerman

swfisher
Posts: 2
Joined: 22 May 2014 12:52

Re: Keep Original File Name When Renaming File Extension

#4 Post by swfisher » 22 May 2014 21:19

Sometimes we can have files with .ps1, .ps2, .ps3 etc. extensions. It's not the same file extension every time. How could I add all of these in the batch file and if it's a file with any of these extensions it will change it to the original file name plus the .ps extension?

Thanks

-stephen

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Keep Original File Name When Renaming File Extension

#5 Post by foxidrive » 22 May 2014 22:27

This will rename any extension that starts with .ps


Code: Select all

 ren *.ps? *.ps

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: Keep Original File Name When Renaming File Extension

#6 Post by Liviu » 22 May 2014 23:58

foxidrive wrote:This will rename any extension that starts with .ps

Off topic, yet can't help but notice that this would incidentally rename .ps1 files (usually associated in Windows with PowerShell) to .ps (PostScript). Yes, I realize that's exactly what's been asked, and guess it must make sense in some context somewhere.

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Keep Original File Name When Renaming File Extension

#7 Post by foxidrive » 23 May 2014 03:20

It's pretty common that nothing you see in a question represents the true task these days. :D

Post Reply