文件名简体转繁体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

 

转载于:https://www.cnblogs.com/zhangdingqu/p/9639956.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值