Advertisement
epl70

Create ranfom files from a file list

Sep 2nd, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. #!/usr/local/bin/python3
  2.  
  3. import os
  4. import random
  5. import sys
  6.  
  7. if len(sys.argv)<3:
  8.     print("Usage file-gen.py filelist, number_of_generated_files");
  9.     sys.exit()
  10.  
  11. random.seed()
  12.  
  13. print("Reading lines from ", sys.argv[1])
  14.  
  15. linecount = 0
  16. lines = []
  17. with open(sys.argv[1]) as f:
  18.     for line in f:
  19.          lines.append(line)
  20.  
  21. filelist = random.sample(lines, int(sys.argv[2]));
  22. for newfile in filelist:
  23.     print("Touching file ", newfile)
  24.     if not os.path.exists(os.path.dirname(newfile)):
  25.         os.makedirs(os.path.dirname(newfile))
  26.     open(newfile.rstrip(), "a+")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement