| | |
| | | |
| | | try { |
| | | # ---------------------------------------------------------------- 1. 要找哪些目录 |
| | | # 要探查的目录放进自己的列表:-Roots 是 [string[]] 定长数组,不能往里 Add。 |
| | | $targets = New-Object System.Collections.ArrayList |
| | | if (-not $Roots -or $Roots.Count -eq 0) { |
| | | Say '=== 1. 自动查找目录 ===' |
| | | $found = New-Object System.Collections.ArrayList |
| | |
| | | } |
| | | foreach ($directory in $found) { |
| | | Say (" 候选目录:" + $directory) |
| | | [void]$Roots.Add($directory) |
| | | [void]$targets.Add($directory) |
| | | } |
| | | if ($Roots.Count -eq 0) { |
| | | if ($targets.Count -eq 0) { |
| | | Say ' 没有找到任何候选目录。请手工指定,例如:-Roots ''D:\<软件目录>''' |
| | | } |
| | | } |
| | | else { Say '=== 1. 指定目录 ===' } |
| | | else { |
| | | Say '=== 1. 指定目录 ===' |
| | | foreach ($root in $Roots) { |
| | | # 用 -File 从命令行传数组时,多个目录可能被当成一个字符串('D:\a,D:\b'),按逗号再拆一次。 |
| | | foreach ($single in @($root -split ',')) { |
| | | $trimmed = $single.Trim().Trim('"') |
| | | if ($trimmed) { Say (" 指定目录:" + $trimmed); [void]$targets.Add($trimmed) } |
| | | } |
| | | } |
| | | } |
| | | |
| | | # ---------------------------------------------------------------- 2. 方案候选文件 |
| | | $candidates = New-Object System.Collections.ArrayList |
| | | foreach ($root in $Roots) { |
| | | foreach ($root in $targets) { |
| | | if (-not (Test-Path -LiteralPath $root)) { Say (" 目录不存在:" + $root); continue } |
| | | Say '' |
| | | Say ("=== 2. 方案候选文件:" + $root + " ===") |