如何使用 PowerShell 中的 Get-ChildItem 僅獲得檔案,而不獲得資料夾?
要僅獲取檔案,你需要在 Directory 屬性引數中使用 NOT 運算子。
示例
Get-ChildItem D:\Temp\ -Attributes !Directory
輸出
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
你可以將不同的選項組合在一起以獲取所需的結果。要僅獲取隱藏檔案,而不獲取資料夾。
Get-ChildItem D:\Temp\ -Attributes !Directory -Hidden
要僅獲取系統 Readonly 檔案,
Get-ChildItem D:\Temp\ -Attributes !Directory –System -Readonly
廣告