Export (0) Print
Expand All
Expand Minimize

Converting the FileSystemObject's GetExtensionName Method


Windows PowerShell


Definition: Given a file name or full path, returns the file extension of the file (without the .).

GetExtensionName


In PowerShell, you can use the Get-Item cmdlet to retrieve a reference to the file, then check the Extension property:


$a = Get-Item c:\scripts\test.txt
$a.extension


You can also do this in one line:


(Get-Item c:\scripts\test.txt).extension


Note that, unlike GetExtensionName, the Extension property includes the dot in the name. In other words, the preceding command will return .txt, not simply txt.


See conversions of other FileSystemObject methods and properties.
Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft