- <# :
- cls
- @echo off
- mode con lines=3000
- set info=互助互利,支付宝扫码头像,感谢赞助
- rem 有问题,可加QQ956535081及时沟通
- title %info%
- set "rootpath=%~dp0"
- if "%rootpath:~-1%" equ "\" (set "rootpath=%rootpath:~,-1%")
- cd /d "%rootpath%"
- powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%rootpath%'"
- echo;%info%
- pause
- exit
- #>
-
- $folder=$args[0];
- $len=30;
-
- $files=@(dir -liter $folder|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($i=0;$i -lt $files.length;$i++){
- $text=[IO.File]::ReadAllText($files[$i].FullName, [Text.Encoding]::Default);
- $s='';$n=0;$m=1;
- for($j=0;$j -lt $text.length;$j++){
- if($text[$j] -match '[^\s\\\/:\*\?"\<\>\|]'){
- $s+=$text[$j];
- $n++;
- if($n -eq $len){break;};
- };
- };
- if($s -ne ''){
- $newname=$s+$files[$i].Extension;
- $newfile=$files[$i].Directory.FullName+'\'+$newname;
- while(test-path -liter $newfile){
- $newname=$s+'_'+$m.toString()+$files[$i].Extension;
- $newfile=$files[$i].Directory.FullName+'\'+$newname;
- $m++;
- };
- write-host $files[$i].FullName -ForegroundColor yellow;
- write-host '-->';
- write-host $newname -ForegroundColor green;
- write-host '';
- };
- };
复制代码
|