Monday, February 9, 2015

Batch file rename with suffix as random alphanumeric

Here is the code which renames all the files in a folder to alphanumeric.


@echo off
setlocal disableDelayedExpansion
set "chars=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
for /f "eol=: delims=" %%F in ('dir /b /a-d *.jpg') do call :renameFile "%%F"
exit /b
:renameFile
setlocal enableDelayedExpansion
:retry
set "name="
for /l %%N in (1 1 8) do (
set /a I=!random!%%36
for %%I in (!I!) do set "name=!name!!chars:~%%I,1!"
)
echo if exist !name!.jpg goto :retry
endlocal & ren %1 %name%.jpg

All you have to do is copy/paste this code and save it .bat file and place in any folders where you want to rename files.


Here is how it works:


example: if filename is lenovo-wallpaper.jpg then it will rename it to AF45ASLJ.JPG


What I want is filename+alphanumeric.jpg


example: if filename is lenovo-wallpaper.jpg then it should be lenovo-wallpaper-adfs45fad1.jpg

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...