SHARE
TWEET

gentextfiles.py

a guest Apr 16th, 2019 11 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. import os
  4. import random
  5. import string
  6.  
  7. # With these settings, it took me 12 minutes to generate. YMMV.
  8. dirs = 10
  9. sublevels = 10
  10. files = 10
  11. filesize = 1024  # in kB
  12. root = '/var/tmp/dirtest'
  13. chars = string.printable
  14.  
  15. def genData():
  16.     for d in range(dirs):
  17.         base = os.path.join(os.path.abspath(root), str(d))
  18.         for s in range(sublevels):
  19.             path = os.path.join(base, str(s))
  20.             os.makedirs(path, exist_ok = True)
  21.             for f in range(files):
  22.                 fpath = os.path.join(path, str(f))
  23.                 with open(fpath, 'a') as fh:
  24.                     fh.write(''.join(random.choice(chars) for i in range((filesize * 1024))))
  25.  
  26. genData()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top