Page 1 of 1

Keep Original File Name When Renaming File Extension

Posted: 22 May 2014 12:58
by swfisher
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

Re: Keep Original File Name When Renaming File Extension

Posted: 22 May 2014 14:10
by Compo
This should do you!

Code: Select all

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

Re: Keep Original File Name When Renaming File Extension

Posted: 22 May 2014 14:12
by aGerman
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

Re: Keep Original File Name When Renaming File Extension

Posted: 22 May 2014 21:19
by swfisher
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

Re: Keep Original File Name When Renaming File Extension

Posted: 22 May 2014 22:27
by foxidrive
This will rename any extension that starts with .ps


Code: Select all

 ren *.ps? *.ps

Re: Keep Original File Name When Renaming File Extension

Posted: 22 May 2014 23:58
by Liviu
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.

Re: Keep Original File Name When Renaming File Extension

Posted: 23 May 2014 03:20
by foxidrive
It's pretty common that nothing you see in a question represents the true task these days. :D