| Home | Site Map | | ||
| CUBISTCODE | ||
|
Python recursive random file function
#!/usr/bin/env python
# recursive_random_file.py
# return random file from complete subdirectory tree
# as passed in from command line options
import os
import sys
import random
fileList = []
rootdir = sys.argv[1]
for root, subFolders, files in os.walk(rootdir):
for file in files:
fileList.append(os.path.join(root,file))
print random.choice(fileList)
Tags: file, functions, python, random, scripts
|
| Home | Site Map | |