<# .SYNOPSIS Gets file extension .DESCRIPTION This script uses the GetExtension method to get a file extension .NOTES File Name : Get-Extension.ps1 Author : Thomas Lee - tfl@psp.co.uk Requires : PowerShell V2 .LINK http://www.pshscripts.blogspot.com .EXAMPLE PSH [C:\foo]: .\get-extension.ps1' GetExtension('C:\mydir.old\myfile.ext') returns '.ext' GetExtension('C:\mydir.old\') returns '' #> ## # Start of Script ## # Set values $fileName = "C:\mydir.old\myfile.ext" $path = "C:\mydir.old\" # Get filename extension $extension = [System.IO.Path]::GetExtension($fileName) "GetExtension('{0}') returns '{1}'" -f $fileName, $extension # Get Path Extension (hint: there is none!) $extension = [System.IO.Path]::GetExtension($path) "GetExtension('{0}') returns '{1}'" -f $path, $extension # End of Script
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Wednesday, 12 November 2008
Get-Extension.ps1
Labels:
GetExtension,
powershell,
Script,
System.IO.Path
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment