第1个回答 2019-10-28
@echo off
rem 删除文件名末尾最后几个字符
set @=Any question&set #=Q&set/az=0x53b7e0b4
title %@% +%#%%#% %z%
set "fd=%~dp0"
cd /d "%fd%"
:input
set "n="&set /p n=输入删除的字符个数:
set direction=右
if not defined n (goto input)
powershell -NoProfile -ExecutionPolicy bypass ^
$files=@(dir -liter '%fd%'^|?{($_.Name -ne '%~nx0') -and ($_ -is [System.IO.FileInfo])}^|sort {$_.FullName.length});^
for($i=0;$i -lt $files.length;$i++){^
$len=$files[$i].BaseName.length-%n%;^
if($len -ge 1){^
$newname=$files[$i].BaseName.SubString(0,$len)+$files[$i].Extension;^
if('%direction%' -eq '左'){$newname=$files[$i].Name.SubString(%n%)};^
$newfile=$files[$i].Directory.FullName+'\'+$newname;^
if(-not (test-path -liter $newfile)){^
write-host ($files[$i].FullName+' --^> '+$newname);^
mv -liter $files[$i].FullName $newfile;^
};^
};^
};
:end
echo;%@% +%#%%#% %z%
pause