我正在审核this question并发现了一些我不理解的内容。
将此文件夹与一个msi文件和一个txt文件一起考虑。为什么Test-Path对msi文件返回false?我期望两个测试路径cmdlet都为$ True,因为这些文件位于文件夹中。
$fldr = 'C:\AMD\WU-CCC2\ccc2_install\CN\amddvr\amddvr64'
$file = 'eval.msi'
$fullPath = Join-Path -Path $fldr -ChildPath $file
Write-Host ' Testing Path to ' $fullPath
Set-Location -Path $fldr
Test-Path -LiteralPath $fullPath
set-location -Path c:\
Test-Path -LiteralPath $fullPath
$file = 'me.txt'
$fullPath = Join-Path -Path $fldr -ChildPath $file
Write-Host ' Testing Path to ' $fullPath
Set-Location -Path $fldr
Test-Path -LiteralPath $fullPath
set-location -Path c:\
Test-Path -LiteralPath $fullPath
这是输出
Testing Path to C:\AMD\WU-CCC2\ccc2_install\CN\amddvr\amddvr64\eval.msi
False
False
Testing Path to C:\AMD\WU-CCC2\ccc2_install\CN\amddvr\amddvr64\me.txt
True
True
如评论所述:
ls $fldr
ls $fldr | % { '-{0}-' -f $_.name }
返回以下内容:
Directory: C:\AMD\WU-CCC2\ccc2_install\CN\amddvr\amddvr64
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 9/27/2017 3:03 PM 8945664 amddvr64.msi
-a---- 10/17/2017 6:21 AM 6 me.txt
和
-amddvr64.msi-
-me.txt-