Advertisement
robertvari

getAllFiles

Jan 27th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. import os
  2.  
  3. def getAllFiles(folder, files=[]):
  4.     # get files and folders in current folder
  5.     allContent = [folder + "/" + i for i in os.listdir(folder)]
  6.  
  7.     # list all files in current folder
  8.     files += [i for i in allContent if i.lower().endswith(".jpg")]
  9.  
  10.     # get subfolders
  11.     subfolders = [i for i in allContent if os.path.isdir(i)]
  12.  
  13.     # recursive call for subfolders
  14.     for f in subfolders:
  15.         getAllFiles(f + "/")
  16.  
  17.     return files
  18.  
  19. for i in getAllFiles("e:/photos"):
  20.     print i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement