2

#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
Filed in: Columns, Tips and Tricks Tags: ,

2 Responses to "#PSTip One way to change a file extension"

Leave a Reply

Submit Comment

© 2016 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: