本帖最后由 zaqmlp 于 2022-4-12 16:03 编辑
- <# :
- cls&echo off&cd /d "%~dp0"&mode con lines=5000
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal \"%~f0\"|out-string|Invoke-Expression"
- pause
- exit
- #>
- $txtfile=".\a.txt";
- $folder="J:\NDM";
- if(-not (test-path -literal $txtfile)){write-host ('"'+$txtfile+'" not found');exit;}
- if(-not (test-path -literal $folder)){write-host ('"'+$folder+'" not found');exit;}
- $text=[IO.File]::ReadAllLines($txtfile, [Text.Encoding]::GetEncoding('GB2312'));
- $files=@(dir -literal $folder -recurse|?{($_.Name -match '^\d+\.pdf$') -and ($_ -is [System.IO.FileInfo])});
- for($i=0;$i -lt $files.length;$i++){
- for($j=0;$j -lt $text.count;$j++){
- if($text[$j].Contains($files[$i].BaseName)){
- if($text[$j] -ne $files[$i].BaseName){
- $newname=($text[$j] -replace '[\t\\\/:\*\?"<>\|]','')+$files[$i].Extension;
- $newfile=$files[$i].Directory.FullName+'\'+$newname;
- write-host ($files[$i].FullName+' --> '+$newname);
- move-item -literal $files[$i].FullName $newfile -force -ErrorAction SilentlyContinue;
- break;
- }
- }
- }
- }
复制代码
|