如何在PowerShell中的Get-ChildItem中排除特定扩展名?
要排除特定扩展名,您需要在Get-ChildItem中使用–Exclude参数。
示例
例如,如下所示,当我们运行命令时,它将排除.html文件并显示其余文件。
Get-ChildItem D:\Temp\ -Recurse -Exclude *.html
输出结果
Directory: D:\Temp
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       24-11-2018     11:31                LGPO
    Directory: D:\Temp\LGPO
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       01-06-2017     03:22         410088 LGPO.exe
-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----       08-12-2017     10:16            393 style.css
-a----       08-12-2017     11:29           7974 Test.xlsx
-a----       25-10-2017     08:13            104 testcsv.csv您也可以排除多个扩展名。
示例
在以下示例中,我们将排除html和xml扩展名。
Get-ChildItem D:\Temp\ -Recurse -Exclude *.html,*.xml
输出结果
Directory: D:\Temp
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       24-11-2018     11:31                LGPO
    Directory: D:\Temp\LGPO
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       01-06-2017     03:22         410088 LGPO.exe
-a----       01-06-2017     02:25         638115 LGPO.pdf
    Directory: D:\Temp
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       08-12-2017     10:16            393 style.css
-a----       08-12-2017     11:29           7974 Test.xlsx
-a----       25-10-2017     08:13            104 testcsv.csv