Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def MultipleTabs(pAmountOfTabs):
- ReturnValue = ""
- for Cnt in range(0, pAmountOfTabs):
- ReturnValue += "\t"
- return ReturnValue
- def GetDataRecursive(pStartingDirectory, pDepth):
- # Do your data gathering or execution of your function here
- #
- # Go to the subfolders and repeat the process
- for Item in os.listdir(pStartingDirectory):
- try:
- FullItemPath= os.path.join(pStartingDirectory, Item) # Item is the basename, so join the directory to get the path
- if os.path.isfile(FullItemPath):
- print("{0} - {1}".format(MultipleTabs(pDepth), Item))
- else:
- print("{0} - {1}".format(MultipleTabs(pDepth), Item))
- GetDataRecursive(FullItemPath, pDepth+1) # Call this function with the subfolder as starting directory
- # and a higher depth
- except:
- print("Permission denied for {0}".format(FullItemPath))
- StartingDirectory = "C:/Test" # The starting folder
- print("Contents of: {0}:\n".format(StartingDirectory))
- GetDataRecursive(StartingDirectory, 0)
Advertisement
Add Comment
Please, Sign In to add comment