choosing random directories in PC using Python
Question: I'm using python 3.x and I don't know how to make my script randomly choose
directories in the same PC to copy files.

I want it to copy the files in the random directories. What should I do to
make it happen?

    
    
    from sys import argv
    
    import os
    
    import random
    
    script=argv
    
    name=str(script[0])
    
    count = 0
    
    i = 10
    while (count < i) :
    
    os.system('start omnomnom.txt')
    count+=1
    
    os.mkdir('tembilaland')
    os.system(r"copy omnomnom.txt tembilaland")
    os.system(r"copy acme.py tembilaland")
    


Answer: I don't know what you are doing that for... honestly :^)

Well, if you don't have a pre-determined list of target directories, you could
use [`os.walk`](https://docs.python.org/2/library/os.html#os.walk) then
[`random.choice`](https://docs.python.org/2/library/random.html#random.choice)
to pick one.

Like:

    
    
    # all subdirectories in the user's home
    directories = [row[0] for row in os.walk(os.path.expanduser('~/subdir'))]
    # or if you want to limit to an arbitrary number
    directories = []
    for i, row in enumerate(os.walk(os.path.expanduser('~'))):
        if i > 100: break
        directories+= [row[0]]
    
    print random.choice(directories)
    

