I\'m trying to do the following:
Rename-Item c:\\misc\\*.xml *.tmp
I basically want to change the extension on every files within a directory t
The existing answers suggest the -replace
operator, but what if the file is called a.xml.xml
? Both .xml
substrings will be replaced and the end result would be a.tmp.tmp
. Fortunately, there's a .NET method for this:
Dir *.xml | rename-item -newname { [io.path]::ChangeExtension($_.name, ".tmp") }
(Manish Kumar was close with GetFileNameWithoutExtension
but this is more elegant and probably a bit more efficient, not that it overly matters in this case)