Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch file to uniquely nmame & random rename JPEG images [randomnames.bat]

460 views
Skip to first unread message

Arlen Holder

unread,
Sep 14, 2020, 9:23:36 PM9/14/20
to
I was re-populating a re-imaged system due to BSOD corrupting the boot
where I had a devil of a time _finding_ this old randomnames.bat file
which will randomly name any number of JPEG files to unique names each.

I use it when I take a bunch of screenshots over long periods of time, and
edit them one by one, as needed, where the names aren't in the order of the
screenshots anyway, and there are too many to rename manually, so I rename
them randomly - which makes each one distinct.

If you need it, it's useful.
o If you don't need it - it's just a sample of randomizing algorithms.

@ECHO OFF
ECHO Random Names
ECHO Written By: Jason Faulkner
ECHO HowToGeek.com
ECHO.
ECHO.
REM
https://www.howtogeek.com/57661/stupid-geek-tricks-randomly-rename-every-file-in-a-directory/
REM https://www.howtogeek.com/wp-content/uploads/2011/04/RandomNames.zip

REM Randomly renames every file in a directory.

SETLOCAL EnableExtensions EnableDelayedExpansion

REM 0 = Rename the file randomly.
REM 1 = Prepend the existing file name with randomly generated string.
SET PrependOnly=0

REM 1 = Undo changes according to the translation file.
REM Undo will only work if a previously generated "__Translation.txt" is in
the same folder.
REM If you delete the translaction file, you will not be able to undo the
changes!
SET Undo=0


REM
--------------------------------------------------------------------------
REM Do not modify anything below this line unless you know what you are
doing.
REM
--------------------------------------------------------------------------

SET TranslationFile=__Translation.txt

IF NOT {%Undo%}=={1} (
REM Rename files
ECHO You are about to randomly rename every file in the following folder:
ECHO %~dp0
ECHO.
ECHO A file named %TranslationFile% will be created which allows you to
undo this.
ECHO Warning: If %TranslationFile% is lost/deleted, this action cannot be
undone.
ECHO Type "OK" to continue.
SET /P Confirm=
IF /I NOT {!Confirm!}=={OK} (
ECHO.
ECHO Aborting.
GOTO :EOF
)

ECHO Original Name/Random Name > %TranslationFile%
ECHO ------------------------- >> %TranslationFile%

FOR /F "tokens=*" %%A IN ('DIR /A:-D /B') DO (
IF NOT %%A==%~nx0 (
IF NOT %%A==%TranslationFile% (
SET Use=%%~xA
IF {%PrependOnly%}=={1} SET Use=_%%A

SET NewName=!RANDOM!-!RANDOM!-!RANDOM!!Use!
ECHO %%A/!NewName!>> %TranslationFile%

RENAME "%%A" "!NewName!"
)
)
)
) ELSE (
ECHO Undo mode.
IF NOT EXIST %TranslationFile% (
ECHO Missing translation file: %TranslationFile%
PAUSE
GOTO :EOF
)
FOR /F "skip=2 tokens=1,2 delims=/" %%A IN (%TranslationFile%) DO RENAME
"%%B" "%%A"
DEL /F /Q %TranslationFile%
)
--
What I love about Usene is it's filled with useful hints & ideas.

Herbert Kleebauer

unread,
Sep 15, 2020, 12:51:32 PM9/15/20
to
On 15.09.2020 03:23, Arlen Holder wrote:

> SET NewName=!RANDOM!-!RANDOM!-!RANDOM!!Use!
> ECHO %%A/!NewName!>> %TranslationFile%
> RENAME "%%A" "!NewName!"

Just because you use %random% 3 times doesn't make it impossible to get
the same name twice. Hopefully you never write SW where live depends on.


> I use it when I take a bunch of screenshots over long periods of time, and
> edit them one by one, as needed, where the names aren't in the order of the
> screenshots anyway, and there are too many to rename manually, so I rename
> them randomly - which makes each one distinct.

This is much easier done with the GUI using explorer. Select all files
you want to rename and click "rename". If you display the files ordered
by date, then also the filenames have this order.


Arlen Holder

unread,
Sep 15, 2020, 1:05:35 PM9/15/20
to
On Tue, 15 Sep 2020 18:51:28 +0200, Herbert Kleebauer wrote:

> Just because you use %random% 3 times doesn't make it impossible to get
> the same name twice. Hopefully you never write SW where live depends on.

Hi Herbert Kleebauer,

Thank you for assessing the script, where I fully agree that it's only
random as much as running pseudo @rand 3 times will make it so. Agreed.

> This is much easier done with the GUI using explorer. Select all files
> you want to rename and click "rename". If you display the files ordered
> by date, then also the filenames have this order.

I had forgotten about that feature of Windows, so again, I thank you for
remaining me, and the others on this newsgroup of the context sensitive
rename menu item.

I just tested it, by the following process, which worked just fine:
a. I selected 75 photos in the Windows explorer
b. I right clicked on one, and selected rename & typed "a"
c. It renamed them successively from "a(1).jpg" to "a(75).jpg"

In addition, while we're listing batch renaming capabilities, Irfanview
freeware has batch renaming capabilities based on regular expressions:
o Irfanview Batch Rename
<http://irfanview.helpmax.net/en/file-menu/batch-conversionrename/>
--
While none are truly random neither Irfanview nor rename seem to be random.

Alan Baker

unread,
Sep 15, 2020, 1:36:10 PM9/15/20
to
Arlen's really not very bright.

Herbert Kleebauer

unread,
Sep 15, 2020, 2:03:47 PM9/15/20
to
On 15.09.2020 19:05, Arlen Holder wrote:

> I just tested it, by the following process, which worked just fine:
> a. I selected 75 photos in the Windows explorer
> b. I right clicked on one,
Don't click on "one", but on the first one of the selected files,
because this one is renamed first and then all other files in the
displayed order.

> and selected rename & typed "a"

Don't type "a" but "a(10001)" to get a proper sequence of file names.

SC Tom

unread,
Sep 17, 2020, 7:13:06 AM9/17/20
to


"Herbert Kleebauer" <kl...@unibwm.de> wrote in message
news:rjqreg$1027$1...@gioia.aioe.org...
That doesn't seem to work in Explorer for me. If I select a number of files
and click "rename" (right-click, rename), it only renames one file. Maybe
because I use StartIsBack?
--

SC Tom


0 new messages