powershell-4.0 - PowerShell gci -Path C:\ -exclude "Windows" -Directory 不显示目录
问题描述
这些是我的根目录:
gci -路径 C:\ -目录
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 1/9/2020 10:35 AM DevResources
d---- 9/12/2018 7:13 AM inetpub
d---- 8/22/2013 10:52 AM PerfLogs
d-r-- 12/11/2019 9:30 AM Program Files
d---- 10/7/2019 2:50 PM Program Files (x86)
d---- 10/3/2018 7:11 AM Projects
d---- 8/22/2019 1:08 PM SymCache
d---- 1/20/2020 10:57 AM temp
d-r-- 12/11/2019 8:58 AM Users
d---- 8/22/2019 2:22 PM Windows
d---- 7/31/2019 10:43 PM Zabbix
但是当我运行时:
gci -Path C:\ -排除“Windows”-目录
我根本没有得到任何结果。这似乎很容易,但我看不出有什么问题。
我正在使用这个结果来管道到另一个命令来查找最大的文件。
解决方案
你是对的。这似乎是一个错误。它在子目录中工作。
gci -path c:\windows -directory -exclude winsxs
它在 6.2.3 的 osx 中给出了一条奇怪的消息:
gci -path / -directory -exclude var
gci : Cannot process argument because the value of argument "path" is not valid. Change the value of the "path" argument and run the operation again.
At line:1 char:1
+ gci -path / -directory -exclude var
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.GetChildItemCommand
或者在 Windows ps 5.1 - 7 中这样:
dir Microsoft.PowerShell.Core\FileSystem::C:\ -exclude windows
dir : Cannot process argument because the value of argument "path" is not valid. Change the value of the "path" argument and run the operation again.
At line:1 char:2
+ dir Microsoft.PowerShell.Core\FileSystem::C:\ -exclude windows
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.GetChildItemCommand
这是一种解决方法,但仅适用于 powershell 6 和 7:
get-item c:\ | get-childitem -exclude windows
推荐阅读
- chart.js - Chart.js noob - 无法显示任何内容
- flutter - 有没有一种干净的方式将任何东西投射到飞镖中的 int 上?
- flutter - 如何使用flutter_swiper保存RadioListTile小部件的各个状态?
- r - R如何找到S3方法?为什么 R 找不到我的 S3 `+` 方法?
- html - html/css 中的图像定位问题
- java - 我不能用 xposed 框架欺骗 Android 设备
- mysql - 大型查询中的 JSON_CONTAINS
- r - 使用 str_replace_all() 替换为完美匹配
- reactjs - 自定义钩子返回 Promise 但在 useEffect 内部解析
- git - 如何将一个 git 存储库的一部分集成为另一个存储库的一部分?