- <#
- .SYNOPSIS
- Changes file extension
- .DESCRIPTION
- This script uses the ChangeExtension method to change a file extension
- .NOTES
- File Name : Change-Extension.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2 CTP3
- .LINK
- http://pshscripts.blogspot.com/2009/03/change-extensionps1.html
- .EXAMPLE
- PSH [C:\foo]: .\Change-Extension.ps1
- Set Extension(C:\mydir\myfile.com.extension,'.old') returns 'C:\mydir\myfile.com.old'
- Set Extension(C:\mydir\myfile.com.extension, '') returns 'C:\mydir\myfile.com.'
- Set Extension(C:\mydir\, '.old') returns 'C:\mydir\.old'
- #>
- ##
- # Start of Script
- ##
- # Setup file names
- $goodFileName = "C:\mydir\myfile.com.extension"
- $badFileName = "C:\mydir\"
- # Change file name extensions
- $result = [System.IO.Path]::ChangeExtension($goodFileName, ".old")
- Set Extension({0},'.old') returns '{1}'" -f $goodFileName, $result
- $result = [System.IO.Path]::ChangeExtension($goodFileName, "")
- Set Extension({0}, '') returns '{1}'" -f $goodFileName, $result
- $result = [System.IO.Path]::ChangeExtension($badFileName, ".old")
- Set Extension({0}, '.old') returns '{1}'" -f $badFileName, $result
- # End of Script
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Tuesday, 10 March 2009
SET-Extension.ps1
Labels:
powershell,
PowerShell scripts,
System.IO.Path
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment