freeware

Threads Posts Archives


<< Previous Thread << Previous Post Topic 15317 of 18074
Posts 7 of 9
Next Post >> Next Thread >>

Re: Randomise files in directory?


de 3c273 06/20/2006 12:50



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-----


"Terry Pinnell" <terrypin@dial.pipex.com> wrote in message
news:nftd9297hc36qls8g46u8mbv9uhkqjam3l@4ax.com...
> 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.
>
> --
> Terry, West Sussex, UK



Randomise files in directory? Terry Pinnell
  Re: Randomise files in directory? Terry Pinnell
  Re: Randomise files in directory? Sietse Fliege
    Re: Randomise files in directory? Sietse Fliege
      Re: Randomise files in directory? Terry Pinnell
        Re: Randomise files in directory? Sietse Fliege
|  Re: Randomise files in directory? 3c273
    Re: Randomise files in directory? 3c273
  Re: Randomise files in directory? Tramp
 
freeware