如何使用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
仅获取系统只读文件,
Get-ChildItem D:\Temp\ -Attributes !Directory –System -Readonly
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短