本帖最后由 5i365 于 2022-2-13 20:32 编辑
最终代码:- cd Task3; $num = 6; [Collections.ArrayList]$src = @()
-
- $dir = gci -dir | where{
- (dir $_ -name) -contains "OK" -and (dir $_ -name) -notcontains "NO"
- }
-
- $src += $dir | foreach{
- dir $_ -exclude OK |
- where{ (dir $_ -name) -contains "YES" }
- }
-
- $des = gci -dir | where{
- (dir $_ -name) -contains "OK" -and (dir $_ -name) -contains "NO"
- }
-
- $des | foreach{
- for ($i = (dir $_ -dir).count; $i -lt $num; $i++)
- {
- if ($src.count -gt 0)
- {
- move $src[0] $_
- $s = $src[0].name
- $s2 = $src[0].parent.name
- ren $_\$s\YES -newname $s2
- $src.removeat(0)
- }
- }
- }
复制代码
|