Powershell-声明其中带有“ $ _pdf”的路径

问题描述

正如标题所述。

我有几个带有“ Test-Path”的if语句,所以如果我立即声明变量会更好。

No agent found in pool pool which satisfies the specified demands:
     FPGA -equals True CI -equals True

文件名一直在变化。这就是为什么我使用“ $ _。pdf”的原因。这只是一个简单的例子。再添加一个文件扩展名即可。代码功能类似于“如果pdf和idx基本名称为真/相等,请移动它们”

这完全可以正常工作,只是为每个if语句放入路径会使它更加混乱。 任何帮助,将不胜感激。预先感谢!

解决方法

Test-Path可以接受一系列要测试的项目。如此使用时,它将返回布尔值数组。如果该数组包含至少一个$false,则至少有一个丢失的文件。如果没有,则所有文件都存在。

一个例子就是这样,

# Create a few test files
set-content foo.idx ''
set-content foo.dpf ''
set-content foo.pub ''

# Instead of foo,you'd populate $s with file's basename
# and use a foreach loop
$s ="foo"

# Test if the trio exists. Note variable $s that contains the basename
if( (Test-Path @(".\$s.idx",".\$s.dpf",".\$s.pub")) -contains $false){
  "nay" # Go here if there was at least one false
}else{
  "aye" # go here if all were true
}
# Output
aye
# Change one extension,so trio doesn't exist
if( (Test-Path @(".\$s.idx",".\$s.bub")) -contains $false) {
  "nay" # Go here if there was at least one false
}else{
  "aye" # go here if all were true
}
# Output
nay
,

我很傻。 我只需要把$path\$_.pdf放在那里。就是这样

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...