Advertisement
Lerax

treeGenerator of all files with just 14lines #Python #Recurs

Jan 31st, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. #generate a list of all archives of the all dirs starting from the execution dir; just 14 lines of code! <3 Python
  2. import os
  3. def treeGenerator(path, list = []):
  4.     files = os.listdir(path)
  5.     for f in files:
  6.         if os.path.isdir(f):
  7.             os.chdir(f)
  8.             newPath = path + '/' + f
  9.             treeGenerator(newPath, list)
  10.             os.chdir('..')
  11.         else:
  12.             list.append(f)
  13.     return list
  14. path = os.getcwd();
  15. print(treeGenerator(path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement