I want to rename 40 png files in one folder, they have very long names. They are named serially like this, "blah...blah...blah160.png", "blah...blah...blah200.png" i.e. after 40 alphanumeric characters comes the serial number in three digits (160), I want only the last three digits to remain in the file name, so, "blah...blah...blah160.png" should become "160.png", is there a simple one line DOS (cmd.exe) command in win 7?
Answer
The following cmd file should do the job:
@echo off & setlocal
for %%F in (*.png) do call :doIt %%F
goto xit
:doIt
set name=%~n1
set num=%name:~-3%
set ext=%~x1
set lentest=%name:~40,3%
if not [%lentest%]==[] (
copy "%1" %num%%ext%
:: del "%1"
)
goto :EOF
:xit
endlocal
Uncomment the "del" line to actually delete the version with the long name.
It is possible to squeeze this in fewer lines, but this would make it less comprehensible.
No comments:
Post a Comment