- 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 only files but not the folders with Get-ChildItem using PowerShell?
To get only files, you need to use NOT operator in Directory attribute parameter.
Example
Get-ChildItem D:\Temp\ -Attributes !Directory
Output
irectory: D:\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 07-05-2018 23:00 301 cars.xml -a---- 29-12-2017 15:16 4526 healthcheck.htm -a---- 29-12-2017 15:16 4526 healthcheck1.htm -ar--- 13-01-2020 18:19 0 Readonlyfile.txt -a---- 08-12-2017 10:24 48362 servicereport.htm -a---- 08-12-2017 10:24 48362 servicereport1.htm -a---- 08-12-2017 10:16 393 style.css -a---- 12-12-2017 23:04 1034 tes.htmoutput.htm -a---- 08-12-2017 11:29 7974 Test.xlsx -a---- 25-10-2017 08:13 104 testcsv.csv
You can combine different options together to get the desired result. To get only hidden files but not the folders.
Get-ChildItem D:\Temp\ -Attributes !Directory -Hidden
To get only, system Readonly files,
Get-ChildItem D:\Temp\ -Attributes !Directory –System -Readonly
- Related Articles
- How to get only folders but not the files in the Get-ChildItem in PowerShell?
- How to get the readonly files using Get-ChildItem in PowerShell?
- How to get only hidden files and folders in PowerShell?
- How to get the system files using the Get-ChildItem in PowerShell?
- How to get hidden files and folders using PowerShell?
- How to list the subfolder contents using Get-ChildItem using PowerShell?
- How to get the list of shared folders using PowerShell?
- How to get the list of empty folders using PowerShell?
- How to use the -recursive parameter in Get-ChildItem using PowerShell?
- How to display files/folders including hidden files/folders in PowerShell?
- How to retrieve files and folders attributes using PowerShell?
- How to change files and folders attributes using PowerShell?
- How to Zip / Unzip files or folders using PowerShell?
- How to delete empty files and folders using PowerShell?
- How to delete hidden files and folders using PowerShell?

Advertisements