Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to get the file extension using PowerShell?
We can retrieve the file extension using multiple ways. First, using the [System.IO.Path] class.
PS C:\> [System.IO.Path]::GetExtension("C:\temp\25Aug2020.txt")
.txt
PS C:\> [System.IO.Path]::GetExtension("C:\temp\azcopy.zip")
.zip
This is the easiest way to get the file extension. Otherways, Using programmatically,
PS C:\> ((Split-Path "C:\Temp\azcopy.zip" -Leaf).Split('.'))[1]
zip
PS C:\> ((Split-Path "C:\Temp\25Aug2020.txt" -Leaf).Split('.'))[1]
txt
Using Get-ChildItem,
PS C:\> (Get-ChildItem C:\Temp\azcopy.zip).Extension .zip PS C:\> (Get-ChildItem C:\Temp\25Aug2020.txt).Extension .txt
Using Get-Item,
PS C:\> (Get-Item C:\Temp\azcopy.zip).Extension .zip
Advertisements
