7

我可以使用经典的 Test-Path 来检查特定文件夹中是否存在名称中包含特定单词的文件?

例如,我想检查是否存在以“LAB”开头的文件。在那个词之后有我无法计算的日期戳。

4

2 回答 2

6

为什么不:

test-path c:\myfolder\lab* -pathtype leaf #leaf is for file (get-help test-path -full)
于 2013-04-12T12:16:25.087 回答
3
$files = Get-ChildItem 'LAB*'
if ($files) {
   Write-Host "Found one."
}
else {
   Write-Host "Not there."
}

Get-ChildItem这依赖于返回匹配文件列表的事实。然后可以评估该列表的“真实性”。

于 2013-04-12T12:06:00.950 回答