- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- Related Articles
- How to get the installed Azure VM extension using PowerShell?
- How to search for a specific extension using Get-ChildItem in PowerShell?
- Golang program to get the file extension
- How to extract file extension using Python?
- How to exclude specific extension in Get-ChildItem in PowerShell?
- How to copy files of the specific extension using PowerShell?
- How to use Get-ChildItem in PowerShell to filter a specific extension?
- How to exclude specific file names using Get-ChildItem in PowerShell?
- Get file extension name in Java
- How to get file extension of file as a result of MySQL query?
- How to retrieve specific file(s) information using Get-ChildItem in PowerShell?
- How to edit the CSV file using PowerShell?
- How to search in the file using PowerShell?
- How to mount the ISO file using PowerShell?
- How to dismount the ISO file using PowerShell?

Advertisements