返回列表 发帖
powershell 不必纠结 bat 特殊字符
  1. $sour = ".\old"
  2. $dest = ".\new"
  3. $ext = "*.txt"
  4. Get-ChildItem -Path $sour -Filter $ext | ForEach-Object {
  5. if ( -Not (Test-Path ( Join-Path  -Path $dest  -ChildPath $_.Name )) ) {
  6. Copy-Item  -Path $_.FullName  -Destination ( Join-Path -Path $dest -ChildPath $_.Name )
  7. } else {
  8. $i = 0
  9. do {
  10. $i++
  11. }
  12. while ( Test-Path ( Join-Path -Path $dest -ChildPath ($_.BaseName + $i + $_.Extension) ) )
  13. Copy-Item  -Path $_.FullName  -Destination ( Join-Path -Path $dest -ChildPath ($_.BaseName + $i + $_.Extension) )
  14. }
  15. }
复制代码

TOP

返回列表