代码之家  ›  专栏  ›  技术社区  ›  Vaethin

get childitem找不到一个特定目录?

  •  1
  • Vaethin  · 技术社区  · 6 年前

    我正在编写一个PowerShell脚本,该脚本应该查看一个目录,按名称(编号的名称)对子目录进行排序,并检查其中是否有特定的文件。如果有的话,它应该被复制到某个地方,如果没有,它应该看看下一个。这是迄今为止我的代码:

    #[...]
    $notExist = $true
    #$LatestCiClient = [some directory from earlier in the script]
    $buildDirectories = Get-ChildItem -Path $LatestCiClient | Sort Name -Descending
    
    while ($notExist) {
        $currentDir = $buildDirectories | Select-Object -First 1
        $assembliesDir = Get-ChildItem -Path $currentDir.FullName -Include Desktop-Assemblies #Breakpoint
        $script:exe = Get-ChildItem -Path $assembliesDir -Include SomeFile.exe | Select -First 1
        if ($Script:exe.Exists) {
            $notExist = $false
        } else {
            if ($buildDirectories.Count -gt 0) {
                $buildDirectories = $buildDirectories | Select -Skip 1
            } else {
                $script:NoneFound = $true
                $script:notExist = $false
            }
        }
    }
    #[more Powershell that is supposed to copy $script:exe] 
    

    我正在获取编号的目录( $buildDirectories ,在调试器中,我看到了整个列表。

    我进入 while block (breakpoint is set at "#Breakpoint"), select the first directory to check ( $currentdir`,这也是正确的),并查找名为“桌面程序集”的文件夹。

    我正在查看它,在资源管理器中,现在,文件夹就在那里,它被填满了,它没有被隐藏(它是只读的,但这不重要?)我没有做任何我在剧本里没做过几次的事-什么都没有。 $assembliesDir 是空的。

    我尝试使用“桌面程序集”,我尝试桌面*,我尝试不使用 -Include . 如果我使用 $currentDir 它说

    找不到路径[weirdpath],因为它不存在

    奇怪的路径是我的文件夹 美元汇率 但路径的其余部分是c:\users\myusername。

    如果我使用 $currentDir.FullName 它会找到所有目录,包括我要查找的目录。我可能应该补充一下,正在搜索的整个目录在另一台计算机上,它是一个网络驱动器。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Sid    6 年前

    你用过这个吗?

    Get-ChildItem -Path $currentDir.FullName | Where-Object {$_.Name -eq 'Desktop-Assemblies'}