[英]Powershell -LiteralPath with wildcard
請嘗試以下操作。
Test-Path 'file1 ``[123].*'
foreach ($f in $files){
$path = "$somepath\$($f.BaseName).*".Replace('[', '``[')
Test-Path -Path $path -PathType Leaf
}
而不是使用 "$somepath\\$($f.BaseName).*" 你可以直接使用 $files 變量本身的文件系統對象的完整路徑,即$files.FullName我希望下面的代碼適合你:)
$files = Get-ChildItem -Recurse -LiteralPath "$somepath"
$files | ForEach-Object {Test-Path -LiteralPath $_.FullName -PathType Leaf}
您剛剛關閉,只需將通配符部分放在 -Filter 參數中並刪除 -PathType
$files = Get-ChildItem -Recurse -LiteralPath "$somepath"
foreach ($f in $files){
Test-Path -LiteralPath "$somepath" -Filter "$($_.BaseName).*"
}
但是您可以像這樣使用 -Path:
-Path `"$somepath\$($_.basename).*`"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.