如何通过文件数组找到tree
,有人居住吗?
posh>
posh> tree ./ | Get-Item
Directory: /home/nicholas/powershell
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 2/21/2021 5:42 PM regex
Get-Item: Cannot find path '/home/nicholas/powershell/regex/├── a.log' because it does not exist.
..
Get-Item: Cannot bind argument to parameter 'Path' because it is an empty string.
Get-Item: Cannot find path '/home/nicholas/powershell/regex/0 directories, 16 files' because it does not exist.
posh>
此示例没有子目录,但对于更复杂的目录,带有子目录,希望捕获每个文件的完整路径和文件名。
具体来说,到那时search https://stackoverflow.com/q/66308742/4531180文件——但问题具有一定的普遍性。
也可以看看:
使用 PowerShell 生成文件和目录列表 https://stackoverflow.com/q/27447014/4531180
https://superuser.com/q/1270040/977796 https://superuser.com/q/1270040/977796
tree
是一个在 Windows 和大多数 Unix 风格的 POS 上发现的 CLI 程序,用于绘制文件结构的可视化表示。它不会生成目录数组。
在 powershell 中,如果您想递归地获取目录结构的项目并将它们保存到变量(除非仅返回单个项目,否则该变量将是一个数组),请使用以下命令:
$tree = Get-ChildItem -Recurse
这会将结果存储在变量中$tree
。
您可以使用-path
如果您想不在当前位置开始,请使用参数。例如。
$tree = Get-ChildItem -Path "/home/dave" -Recurse
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)