2

この Web サイトによると、すべてのフォルダーはコンテナーである必要があるため、次の条件を満たす必要があります。

if (Test-Path $item -PathType Container) 
{
    "TRUE: " + $item.Name
} 
else 
{ 
    "FALSE: " + $item.Name
}

しかし、私にとってはそうではありません。一部のフォルダーは真であり、他のフォルダーは偽です。これは私のスクリプト全体です:

function GetFiles($path = $pwd) 
{ 
    foreach ($item in Get-ChildItem $path)
    {
        $item;
        if (Test-Path $item -PathType Container) 
        {
            "TRUE: " + $item.Name
            GetFiles $item.FullName
        } 
        else 
        { 
            "FALSE: " + $item.Name
        }
    } 
}

関数が時々 false を返すのはなぜですか?

更新:たとえば、これは私がそれが真実であると期待するケースです:

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         9/10/2013   1:51 PM            Assets
FALSE: Assets
4

2 に答える 2

1

$item.FullName必要とされている ;)

function GetFiles($path = $pwd) 
{ 
    foreach ($item in Get-ChildItem $path)
    {
        if (Test-Path -LiteralPath $item.FullName -PathType Container)
        {
            "TRUE: " + $item.Name
            GetFiles $item.FullName
        } 
        else 
        { 
            "FALSE: " + $item.Name
        }
    } 
}
于 2013-09-17T21:08:53.660 に答える