我想编写一个PowerShell脚本,它将递归搜索目录,但排除指定的文件(例如,* .log和myFile.txt),并排除指定的目录及其内容(例如,myDir和所有文件和myDir下面的文件夹)。 我一直在使用 Get
我一直在使用Get-ChildItem CmdLet和Where-Object CmdLet,但我似乎无法得到这种确切的行为。
function GetFiles($path = $pwd, [string[]]$exclude)
{
foreach ($item in Get-ChildItem $path)
{
if ($exclude | Where {$item -like $_}) { continue }
if (Test-Path $item.FullName -PathType Container)
{
$item
GetFiles $item.FullName $exclude
}
else
{
$item
}
}
}
