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
-
Economics & Finance
Selected Reading
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
Advertisements
