powershell 不必纠结 bat 特殊字符- $sour = ".\old"
- $dest = ".\new"
- $ext = "*.txt"
-
- Get-ChildItem -Path $sour -Filter $ext | ForEach-Object {
- if ( -Not (Test-Path ( Join-Path -Path $dest -ChildPath $_.Name )) ) {
- Copy-Item -Path $_.FullName -Destination ( Join-Path -Path $dest -ChildPath $_.Name )
- } else {
- $i = 0
- do {
- $i++
- }
- while ( Test-Path ( Join-Path -Path $dest -ChildPath ($_.BaseName + $i + $_.Extension) ) )
- Copy-Item -Path $_.FullName -Destination ( Join-Path -Path $dest -ChildPath ($_.BaseName + $i + $_.Extension) )
- }
-
- }
复制代码
|