如何在 PowerShell 中使用 Get-ChildItem 排除特定檔名?


要從 Get-ChildItem 的輸出中排除特定檔案,您需要指定檔名。

命令

Get-ChildItem D:\Temp\ -Recurse -Exclude style.css, LGPO.exe

輸出

Directory: D:\Temp\LGPO
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       01-06-2017     02:25         638115 LGPO.pdf
    Directory: 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----       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\ -Recurse -Exclude LG*

以上命令將排除所有以 LG 開頭的檔案和資料夾。

更新於: 2020 年 1 月 23 日

3K+ 瀏覽量

開啟您的 職業生涯

完成課程以獲得認證

開始
廣告