本帖最后由 for_flr 于 2021-12-17 17:38 编辑
- $d1="C:\Users\lenovo\Desktop\1"
- $d2="C:\Users\lenovo\Desktop\2"
- $dir1=Get-ChildItem $d1|Where-Object{$_.PSIsContainer -eq $true}
- $dir2=Get-ChildItem $d2|Where-Object{$_.PSIsContainer -eq $true}
- $num=$dir1.Count / $dir2.Count
- $num=[math]::Truncate($num)
- $mod=$dir1.Count % $dir2.Count
- $begin=0
- $end=$num
- $begin2=0
- $end2=$num-1
-
- for ($a=0;$a -lt $dir2.Count;$a++){
- if ($a -lt $mod){
- Copy-Item $dir1[$begin..$end].fullname $dir2[$a] -WhatIf
- $begin+=$num+1
- $end+=$num+1
- $begin2=$begin
- $end2=$begin2+$num-1
-
- }else{
- Copy-Item $dir1[$begin2..$end2].fullname $dir2[$a] -WhatIf
- $begin2+=$num
- $end2+=$num
- }
- }
复制代码 powershell,测试没问题的话,就把-whatif 删掉 |