返回列表 发帖

(已解决)+30求助,批量去除子文件夹中照片名的英文字母

本帖最后由 hxc1995 于 2021-11-10 16:50 编辑

+30求助,批量去除子文件夹中照片名的英文字母

回复 1# hxc1995
@echo off
setlocal enabledelayedexpansion
cd /d "%~dp0"
for /f "delims=" %%i in ('dir /b /s /a-d *.jpg *.png') do (
    set "FileName=%%~ni"
    for %%j in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
        set "FileName=!FileName:%%j=!"
    )
    if "%%~nxi" neq "!FileName!%%~xi" (
        ren "%%i" "!FileName!%%~xi"
    )
)COPY
请参考Q-04把bat文件保存为ANSI编码:
https://mp.weixin.qq.com/s/6lbb97qUOs1sTyKJfN0ZEQ
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

<# :
cls&echo off&cd /d "%~dp0"&mode con lines=3000
rem 另存为ANSI编码
powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
pause
exit
#>
$path=get-item -literal ".";
$files=@(dir -liter $path -recurse|?{(@('.jpg','.jpeg','.bmp','.png','.tif') -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])});
for($i=0;$i -lt $files.length;$i++){
    $base=($files[$i].BaseName -replace '[a-z]','').trim();
    if(($base -ne '') -and ($base -ne $files[$i].BaseName)){
        $newname=$base+$files[$i].Extension;
        $newfile=$files[$i].Directory.FullName+'\'+$newname;
        $n=2;
        while(test-path -literal $newfile){
            $newname=$base+' ('+$n.toString()+')'+$files[$i].Extension;
            $newfile=$files[$i].Directory.FullName+'\'+$newname;
            $n++;
        }
        write-host ($files[$i].FullName+' --> '+$newname);
        move-Item -liter $files[$i].FullName $newfile -force -ErrorAction SilentlyContinue;
    }
}COPY
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

回复 2# Batcher


    感谢管理大大

TOP

返回列表