A simple Python script to get a random file in a directory.

#!/usr/bin/python
import random
import os
import sys
 
def usage(status):
    print """Usage: randfile <dir>"""
    print """Gets a random file from DIR."""
    
    sys.exit(1)
 
if len(sys.argv) != 2:
    usage(1)
 
try:
    print random.choice(os.listdir(sys.argv[1]))
except OSError, msg:
    print "randfile: error getting random file: %s" % msg
    sys.exit(1)
 
random-file-py.txt · Last modified: 2005/07/29 01:43 by vijaykumar
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
This work is licensed under the GNU Free Documentation License..