BAT代码:批量文件下划线重命名

话不多说,直接上图,你们就知道是不是自己想要的代码了

我需要让目录下的文件全部加上“_简历”的后缀,方便归档处理

文件截图:

代码运行:

运行结果:

 规则很清晰哈,就不多做解释!

代码如下:

<# :
cls&echo off&cd /d "%~dp0"&rem 编码ANSI
set "current=%cd%"
powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText(\"%~f0\",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
pause
exit
#>
$suffix="_简历"
$current=get-item -literal $env:current;
$files=@(dir -literal $current|?{('.bat' -ne $_.Extension) -and ($_ -is [System.IO.FileInfo])});
for($i=0;$i -lt $files.length;$i++){
    $m=[regex]::match($files[$i].BaseName.replace($suffix, ''), '[\u4E00-\u9FA5]+');
    if($m.Success){
        $newname=$m.groups[0].value+$suffix+$files[$i].Extension;
        if($newname -ne $files[$i].Name){
            $newfile=$files[$i].Directory.FullName+'\'+$newname;
            write-host ($files[$i].Name+' --> '+$newname);
            move-item -literal $files[$i].FullName $newfile -ErrorAction SilentlyContinue;
        }
    }
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值