本帖最后由 pcl_test 于 2017-5-3 02:39 编辑
- @echo off
- powershell ^
- $fileList='1.txt';^
- $notExists='2.txt';^
- $srcFolder='D:\文件夹1\';^
- $desFolder='D:\文件夹2\4567';^
- $m=@{};$s='';^
- if(-not (Test-Path -Literal $desFolder)){md $desFolder^|out-null};^
- gc $fileList^|?{$_ -notmatch '^^\s*$'}^|%%{if(!$m[$_.trim().ToLower()]){$m[$_.trim().ToLower()]=1;}};^
- dir -Literal $srcFolder -r^|?{$_ -is [System.IO.FileInfo]}^|%%{^
- $tmp=$_.Name.ToLower();^
- if($m[$tmp]){^
- if($m[$tmp] -le 1){^
- cp -Literal $_.FullName $desFolder -Force;^
- }else{^
- ^<#处理同名文件#^>^
- $newname=$_.BaseName+'_('+($m[$tmp]-1)+')'+$_.Extension;^
- cp -Literal $_.FullName (Join-Path $desFolder $newname) -Force;^
- };^
- $m[$tmp]+=1;^
- };};^
- foreach($a in $m.keys){if($m[$a] -eq 1){$s+=$a+\"`r`n\";}};^
- if($s){Set-Content $notExists -value $s}
- pause
复制代码
|