Randomise files in directory?

T

Terry Pinnell

Does anyone know of a program that will input a selection of files in
a Windows folder (or all of them), and randomly change all their
filenames please?

What prompts this apparently odd requirement is that I have a program
called Dockware for my Pocket PC which sequentially displays all the
JPGs in a specific folder. I've loaded that folder by copying from my
PC, so there are many 'blocks' of similar photos (such as holidays,
the kids, etc.) I'd like them to be displayed less predictably, so
need to rename them randomly. Dockware itself has no facility to do
that.

IOW, I want to take files like

France2002-01.jpg
France2002-03.jpg
France2002-04.jpg
Spain 1997-09.jpg
Spain 1997-13.jpg
etc

and end up with say

xgh3.jpg
2frt.jpg
qq4k.jpg
1hfd.jpg
zxur.jpg
etc

When displayed alphabetically, these will then effectively be
randomised.
 
T

Tramp

|Does anyone know of a program that will input a selection of files in
|a Windows folder (or all of them), and randomly change all their
|filenames please?

I did the same thing with some MP3's. I wanted to make a "random"
selection to burn as audio. I use a program called THE Rename
http://www.herve-thouzard.com/modules/wfsection/article.php?articleid=1

open the program
browse to the files you want to rename
click on the NAMING RULES (on the right side)
use the drop down menu under PREFIX, choose FREE FORM
expand the GENERAL tree
scroll down and double click on <RandomPrefix>
You will see <RandomPrefix> up at the top of the list. Add the file
extension of the files you want to rename. For example when I did mine I
added .mp3 (don't forget the .) So if you are using it for jpg's then
add .jpg
run the program

I made mine even more random by adding files a little at a time. I
copied a few songs from each band into an empty folder and then renamed
them. I did that a few times. I then added all the renamed files into
one folder and renamed them once again.
 
3

3c273

If you have Python installed (www.python.org), the following script will do
what you need. You just need to insert your directory name where indicated.
I used five characters because this script will fail if the filname already
exists under windows. It should be safe for several thousand files. Make
sure you have a backup, I have tested this a few times but you are
responsible for your own data. BACKUP! Save the script as "renamer.py" and
run the command "python renamer.py" from the directory where you saved it.
Post back if you have questions.
Louis

-----begin script-----
import os
import random

mypath= 'c:/temp/test/' ##insert the path to your files
##between the quotes
##using forward slashes
##don't forget last slash
def randomName():
a = random.randint(97, 122)
b = random.randint(97, 122)
c = random.randint(97, 122)
d = random.randint(97, 122)
newname = chr(a) + chr(b) + chr(c) + chr(d) + '.jpg'
return newname

for files in os.listdir(mypath):
os.rename(os.path.join(mypath, files), \
os.path.join(mypath, randomName()))
-----end script-----
 
3

3c273

3c273 said:
I used five characters because this script will fail if the filname already
exists under windows. It should be safe for several thousand files.

Oops, that was four characters. Here it is with 5 characters.
Louis

-----begin script-----
import os
import random

mypath= 'c:/temp/test/' ##insert the path to your files
##between the quotes
##using forward slashes
##don't forget last slash
def randomName():
a = random.randint(97, 122)
b = random.randint(97, 122)
c = random.randint(97, 122)
d = random.randint(97, 122)
e = random.randint(97, 122)
newname = chr(a) + chr(b) + chr(c) + chr(d) +chr(e) + '.jpg'
return newname

for files in os.listdir(mypath):
os.rename(os.path.join(mypath, files), \
os.path.join(mypath, randomName()))
-----end script-----
 
T

Terry Pinnell

Terry Pinnell said:
Does anyone know of a program that will input a selection of files in
a Windows folder (or all of them), and randomly change all their
filenames please?

What prompts this apparently odd requirement is that I have a program
called Dockware for my Pocket PC which sequentially displays all the
JPGs in a specific folder. I've loaded that folder by copying from my
PC, so there are many 'blocks' of similar photos (such as holidays,
the kids, etc.) I'd like them to be displayed less predictably, so
need to rename them randomly. Dockware itself has no facility to do
that.

IOW, I want to take files like

France2002-01.jpg
France2002-03.jpg
France2002-04.jpg
Spain 1997-09.jpg
Spain 1997-13.jpg
etc

and end up with say

xgh3.jpg
2frt.jpg
qq4k.jpg
1hfd.jpg
zxur.jpg
etc

When displayed alphabetically, these will then effectively be
randomised.

Sorted (!) thanks. Jim Willsher's excellent Bulk Rename Utility
includes a Randomise facility.
 
S

Sietse Fliege

Terry said:
Thanks for all the helpful suggestions. Sorry I wasn't fast enough
with my own BRU solution to save you all the trouble.

No trouble at all, Terry, as I happened to come across these two
renamers and remembering your query I just checked their features list
to see if they offered randomising of some sort.
The info will probably be of use to someone, if not for myself. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top