本帖最后由 pd1 于 2023-2-7 18:15 编辑
保存为A.bat后运行,会生成一个B.bat和hash.bat(这个就是保存的一个hash表),然后你运行你的改名,最后运行B.bat恢复试试。- <# :
- @echo off
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0' |Out-String|Invoke-Expression"
- pause
- #>
- $bat=@'
- <# :
- @echo off
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0' |Out-String|Invoke-Expression"
- pause
- #>
- $ss=ConvertFrom-Json -InputObject (Get-Content .\hash.bat)
- dir -s|Where-Object{$_.Extension -ne ".bat" -and $_ -is [System.IO.FileInfo]}|ForEach-Object{$h=(Get-FileHash -Path $_.FullName -Algorithm MD5).hash;ren $_.FullName $ss.$h.Replace((Split-Path $ss.$h).ToString()+"\","")}
- '@
- $bat|Out-File -Append -Encoding default -FilePath B.bat
- $s="{"
- dir -s|Where-Object{$_.Extension -ne ".bat" -and $_ -is [System.IO.FileInfo]}|ForEach-Object{$s+='"'+(Get-FileHash -Path $_.FUllName -Algorithm MD5).hash+'":"'+$_.FullName.replace("\", "\\")+'",'}
- $s=$s.Substring(0,$s.Length-1)+"}"
- $s|Out-File -Append -FilePath hash.bat
复制代码
|