pestiand82

recursion

Sep 22nd, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2.  
  3. def get_factorial(n):
  4.     # terminate function
  5.     if n < 2:
  6.         return n
  7.  
  8.     else: #recursion
  9.         return n * get_factorial(n-1)
  10.  
  11. # print( get_factorial(7) )
  12.  
  13. # get all files in subfolders
  14. def get_all_files(root_folder, file_list=[]):
  15.     all_content = [os.path.join(root_folder, i) for i in os.listdir(root_folder)]
  16.  
  17.     # get files from current folder
  18.     file_list += [i for i in all_content if os.path.isfile(i)]
  19.  
  20.     subfolders = [i for i in all_content if os.path.isdir(i)]
  21.  
  22.     for folder in subfolders:
  23.         get_all_files(folder)
  24.  
  25.     return file_list
  26.  
  27.  
  28. all_files = get_all_files(r"E:\Photos")
  29. for i in all_files:
  30.     print(i)
Add Comment
Please, Sign In to add comment