繁体   English   中英

Get-ChildItem找不到文件

[英]Get-ChildItem not finding files

我试图递归地查找文件夹中的文件,我已将文件名放入Array中,但Get-ChildItem找不到文件。 我可以将$ ImageNames变量替换为实际的字符串名称,并找到它们。 因此,我知道该变量有问题,但我无法查明它是什么。 这是脚本的片段。

我试图将数组拆分为foreach,但是使用单个字符串会得到相同的结果。

Current output of $ImageNames from Write-Output of $imageNames
TEST_###_DPm.X.1.2.840.113681.2886735633.1532516094.5056.994912425400525861.dcm
TEST_###_DPm.X.1.2.840.113681.2886735633.1532516094.5056.996112425422850002.dcm
TEST_###_DPm.X.1.2.840.113681.2886735633.1532516094.5056.997312425470276903.dcm

已根据建议更新,但仍无法正常工作

foreach ($xmlFile in $sumReportArray)
    {

        $outputDirectory = $patientDir
        $subDirPerXML = Split-Path -Path $xmlFile -Leaf -Resolve
        $finalDir = $outputDirectory + '\' + $subDirPerXML
        [xml]$XmlDocument = Get-Content $xmlFile

        New-Item -ItemType Directory -Force -Path $finalDir | Out-Null
        $imageNames = $XmlDocument.VOLPARA_SERVER_INTERFACE.VolparaDicomSummaryReport.VolparaInputs.Image | Select-Object -ExpandProperty ImageFileName 
        Get-ChildItem -LiteralPath $volparaPath -include $imageNames -Recurse | Copy-Item -Destination $finalDir
    }

这是我得到的错误...

 Get-ChildItem : Illegal characters in path. At C:\\Users\\AdamZenner\\OneDrive - Volpara Health Technologies Limited\\1 Volpara\\Production Software\\Script_VolparaServerSearch\\VolparaServerSearch_1.0.ps1:90 char:13 + Get-ChildItem -recurse -Path ($volparaPath) -filter ($ima ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (C:\\Program File...araServer\\DATA\\:String) [Get-ChildItem], ArgumentException + FullyQualifiedErrorId : DirArgumentError,Microsoft.PowerShell.Commands.GetChildItemCommand 

... | Select ImageFileName | Out-String的输出 ... | Select ImageFileName | Out-String ... | Select ImageFileName | Out-String包含不必要的字符串。 (标题,分隔符等)

因此,您应该使用Select-Object -ExpandProperty

$imageNames = … | Select-Object -ExpandProperty ImageFileName

但是在这种情况下,使用点访问就足够了。

如果$imageNames是一个数组,则使用-Include参数而不是-Filter参数。

$imageNames = $XmlDocument.VOLPARA_SERVER_INTERFACE.VolparaDicomSummaryReport.VolparaInputs.Image.ImageFileName
Get-ChildItem -Path $volparaPath -Include $imageNames -Recurse | Copy-Item -Destination $finalDir

只需从所有变量中删除括号(),它就可以工作。

New-Item -ItemType Directory -Force -Path ($finalDir)

New-Item -ItemType Directory -Force -Path $finalDir

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM