存为test.bat- <# :
- cls&echo off&cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal \"%~f0\"|Out-String|Invoke-Expression"
- pause
- exit
- #>
- $oldfolder="C:\test\";
- $newfolder="D:\";
- if(-not (test-path -literal $newfolder)){[void][IO.Directory]::CreateDirectory($newfolder);}
- $files=@(dir -literal $oldfolder -recurse|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($i=0;$i -lt $files.length;$i++){
- $n=2;
- $newfile=$newfolder.trimend('\')+'\'+$files[$i].Name;
- while(test-path -literal $newfile){
- $newfile=$newfolder.trimend('\')+'\'+$files[$i].BaseName+' ('+$n.ToString()+')'+$files[$i].Extension;
- $n++;
- }
- copy-item -literal $files[$i].FullName $newfile -force -ErrorAction SilentlyContinue;
- }
复制代码
|