#PSTip One way to change a file extension

Modifying a file always brings a risk of corrupting it; making a backup copy whenever possible is one of the file manipulation best-practices. One way of doing it is to create a copy with the same name and appropriate extension like ‘bak’. This task can be finished in a few different ways. Here is my favorite–using the Copy-Item cmdlet and the ChangeExtension() method of the System.IO.Path class:

$path = 'C:\temp\ImportantFile.txt'
Copy-Item -Path $path –Destination ([io.path]::ChangeExtension($path, '.bak')) -Verbose

About the author: Jakub Jareš

Jakub Jareš is an IT professional with strong background in Windows desktop systems. He started with Powershell a few months ago, and couldn't let go ever since. Showing that with the right attitude, a bit of effort and lot of practice you can become advanced in Powershell in no time.

Related Posts

%d bloggers like this: