文件名簡體轉繁體bat


@echo off
rem 指定文件夾路徑
set fd=D:\下載的圖片
rem 0為轉換文件名,1為轉換文件夾名,2為同時轉換文件名和文件夾名
set f=0

rem 0為不包括子文件夾,1為包括子文件夾
set r=1
rem 2為繁轉簡,4為簡轉繁
set n=4
set locale=[System.Globalization.Cultureinfo]::CurrentCulture.LCID
if "%fd:~-1%" equ "\" set "fd=%fd:~,-1%"
if "%r%" equ "1" (set r=-r) else set "r="
if "%f%" equ "0" (set "f=$_.PSIsContainer -eq $false") else (
  if "%f%" equ "1" (set "f=$_.PSIsContainer -eq $true") else set "f=1 -eq 1"
)

powershell ^
  \">> %fd%`r`n\"+('-'*45);^
  $cs='^
  using System;^
  using System.Runtime.InteropServices;^
  public static class ToConvert^
  {^
  [DllImport(\"kernel32\", CharSet = CharSet.Unicode, SetLastError = true)]^
  public static extern int LCMapString(int Locale, int dwMapFlags, string lpSrcStr, int cchSrc, string lpDestStr, int cchDest);^
  }';^
  Add-Type -TypeDefinition $cs;^
  ls -Path '%fd%' %r%^|?{%f%}^|sort {$_.FullName.Length} -des^|^
  %%{$scr=$_.Name;$len=$scr.Length;$des=' '*$len;^
  [ToConvert]::LCMapString(%locale%, 0x0%n%000000, $scr, $len, $des, $len)^|out-null;^
  if($scr -ne $des){^
  $fd=[IO.Directory]::GetParent($_.FullName).FullName+'\';^
  $newname=$fd+$des;^
  $n=0;^
  while(Test-Path -LiteralPath $newname)^
  {^
  $n++;^
  if($_.PSIsContainer){^
  $newname=$fd+$des+'_'+$n;^
  }else{^
  if($des -match '(.+)(\.[^^\.]+$)'){$tmp=$matches[1]+'_'+$n+$matches[2]}else{$tmp=$des+'_'+$n}^
  $newname=$fd+$tmp;^
  }^
  }^
  mv -literalpath $_.FullName $newname;^
  if(Test-Path -LiteralPath $_.FullName){$ts='*轉換失敗,需手動重命名';}else{$ts=$newname.Split('\')[-1];}^
  $_.FullName.ToLower().replace('%fd%'.ToLower(),'')+' ==^> '+$ts;^
  }^
  }
pause

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM