Guest User

Example for valerio92

a guest
Jun 5th, 2016
1,126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import os
  2.  
  3. def MultipleTabs(pAmountOfTabs):
  4. ReturnValue = ""
  5. for Cnt in range(0, pAmountOfTabs):
  6. ReturnValue += "\t"
  7. return ReturnValue
  8.  
  9. def GetDataRecursive(pStartingDirectory, pDepth):
  10. # Do your data gathering or execution of your function here
  11. #
  12. # Go to the subfolders and repeat the process
  13. for Item in os.listdir(pStartingDirectory):
  14. try:
  15. FullItemPath= os.path.join(pStartingDirectory, Item) # Item is the basename, so join the directory to get the path
  16. if os.path.isfile(FullItemPath):
  17. print("{0} - {1}".format(MultipleTabs(pDepth), Item))
  18. else:
  19. print("{0} - {1}".format(MultipleTabs(pDepth), Item))
  20. GetDataRecursive(FullItemPath, pDepth+1) # Call this function with the subfolder as starting directory
  21. # and a higher depth
  22. except:
  23. print("Permission denied for {0}".format(FullItemPath))
  24.  
  25. StartingDirectory = "C:/Test" # The starting folder
  26. print("Contents of: {0}:\n".format(StartingDirectory))
  27. GetDataRecursive(StartingDirectory, 0)
Advertisement
Add Comment
Please, Sign In to add comment