gpt4 book ai didi

powershell - 使用通配符从路径中获取实际路径

转载 作者:行者123 更新时间:2023-12-03 09:42:17 24 4
gpt4 key购买 nike

Test-Path 语句中使用 if 时,我希望获得 if 语句成功的路径。

例如,这些文件存在于 C 中:

C:\Test6_1_15.txt
C:\Test6_2_15.txt
C:\Test6_3_15.txt
C:\Test6_4_15.txt

我在“then”分支做什么?

$Path = "C:\Test6_*_15.txt"
if (Test-Path $Path)
{
# if test passes because there are 4 files that fit the test, but I want to be
# able to output the file that made the if statement succeed.
}

最佳答案

听起来你想要 Resolve-Path :

if(($Paths = @(Resolve-Path "C:\Test6_*_15.txt"))){
foreach($file in $Paths){
# do stuff
}
} else {
# Resolve-Path was unable to resolve "C:\Test6_*_15.txt" to anything
}

关于powershell - 使用通配符从路径中获取实际路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30894718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com