How to batch rename files with a random name

I have a bunch of photos with varying names.
I want to give each photo a random name(*), how do I do that?

(*)I'm going to put them on a digital photo-frame that can't shuffle

5

4 Answers

Assuming all the images are in a single folder, this would work in powershell:

Get-ChildItem *.jpg | ForEach-Object{Rename-Item $_ -NewName "$(Get-Random)-$($_.Name).jpg"}

It is possible that you would get potential name collisions, but Get-Random by default returns a 32 bit unsigned int from 0 to Int32.MaxValue (0 to 2147483647). You could certainly add another Get-Random in to reduce the likelihood of a collision just as in the Bash answer.

1

One way if you have a bash shell handy is to use the $RANDOM environment variable. It generates random values between 0 and 32767.

A simple for loop in bash works fine if you only have a few hundred files.

for i in *.jpg; do mv -i "$i" ${RANDOM}.jpg; done

Since I had about 4000 files to rename I soon got collisions that the -i flag to mv caught. Adding another $RANDOM took care of that.

for i in *.jpg; do mv -i "$i" ${RANDOM}${RANDOM}.jpg; done
4

for f in *; do ext=$(echo "$f" | sed 's|\([^.]*\)||'); mv "$f" "$(uuidgen)$ext"; done

1

Most batch file renamers can do this, here is one

Easy method would be to do a sequential numbering of the file, I am sure there other options with this software, use your imagination.

Here is the one I use for bulk renaming tasks

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like