我可以使用经典的 Test-Path 来检查特定文件夹中是否存在名称中包含特定单词的文件?
例如,我想检查是否存在以“LAB”开头的文件。在那个词之后有我无法计算的日期戳。
我可以使用经典的 Test-Path 来检查特定文件夹中是否存在名称中包含特定单词的文件?
例如,我想检查是否存在以“LAB”开头的文件。在那个词之后有我无法计算的日期戳。
为什么不:
test-path c:\myfolder\lab* -pathtype leaf #leaf is for file (get-help test-path -full)
$files = Get-ChildItem 'LAB*'
if ($files) {
Write-Host "Found one."
}
else {
Write-Host "Not there."
}
Get-ChildItem
这依赖于返回匹配文件列表的事实。然后可以评估该列表的“真实性”。