【问题标题】:Powershell how to get the full path of a folder that is deep in the folder structure by knowing only the beginning of the pathPowershell如何通过仅知道路径的开头来获取文件夹结构深处的文件夹的完整路径
【发布时间】:2018-11-29 13:36:10
【问题描述】:

请任何人告诉我如何使用 Powershell 命令获取特定文件夹的路径,该命令在文件夹结构中大约 10、15 个位置。

例如在以下文件夹结构中

C:\Folder1\Folder2\Folder3\...\....\....\....\....\.....\....\....\...\MyFolder

在这里,我可以访问起始文件夹路径,即。

C:\Folder1\Folder2\Folder3\

但我不知道缺少的 ...\...\....\ 文件夹。

我想获取 MyFolder 的完整路径。对 Powershell 有帮助吗?

【问题讨论】:

    标签: powershell


    【解决方案1】:

    试试这个:

    get-childitem -Path 'c:\Folder1' -Directory -Recurse | ? {$_.Basename -eq 'MyFolder'} | Select FullName
    

    或者:

    get-childitem -Path 'C:\folder1' -Directory -Recurse -Filter 'MyFolder' | Select FullName
    

    【讨论】:

    • 感谢@Sceptalist。没有尝试过第一个命令,但第二个让我在 Powershell 命令行中获得了完整路径,但是当我在 C# 代码中使用相同的命令以及源文件中的其他 powershell 命令时,它什么也没做。有什么帮助吗?
    • 过滤器命令依赖于 PS 文件系统提供程序可用。可能更容易使用第一个命令,但它有点慢。
    猜你喜欢
    • 2020-12-19
    • 2015-06-15
    • 1970-01-01
    • 2019-10-21
    • 1970-01-01
    • 2011-07-10
    • 2012-10-19
    • 2020-08-09
    • 2014-06-08
    相关资源
    最近更新 更多