本帖最后由 zaqmlp 于 2020-6-7 13:07 编辑
- <# :
- cls
- @echo off
- mode con lines=5000
- cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~dp0'"
- pause
- exit
- #>
- $path=$args[0];
- $txtfile=$path+"a.txt";
- if(-not (test-path -liter $txtfile)){Write-host ('"'+$txtfile+'" not found');exit;};
- $text=[IO.File]::ReadAllLines($txtfile,[Text.Encoding]::Default);
- $files=@(dir -liter $path -recurse|?{$_ -is [System.IO.FileInfo]});
- for($i=0;$i -lt $files.length;$i++){
- for($j=0;$j -lt $text.Count;$j++){
- $arr=$text[$j].split('—');
- if($arr.length -ge 2){
- if($files[$i].BaseName.Contains($arr[1])){
- $newname=$arr[0]+$files[$i].Extension;
- $newfile=$files[$i].Directory.FullName+'\'+$newname;
- write-host $files[$i].FullName;
- write-host '-->';
- write-host $newname;
- write-host '';
- mv -liter $files[$i].FullName $newfile;
- break;
- };
- };
- };
- }
复制代码
|