freeware

Threads Posts Archives


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

Re: Randomise files in directory?


de 3c273 06/20/2006 01:05



"3c273" <nospam@nospam.com> wrote in message
news:e779n10abe@enews2.newsguy.com...
> 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-----



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