2

I'm trying to list all the subdirectories of a specific path something like this

rootdir = 'build/system/'
def list_dirs(rootdir):
  for dir in os.scandir(rootdir):
        if not os.listdir(rootdir):
            sys.exit("Directory is empty")
            if dir.is_dir():
                #do something

        list_dirs(rootdir)   

It has a large number of subdirectories hence I think it's not able to do the necessary action after the recursive call. Getting the following error, how to fix this issue, is there a better way to address this recursive call

ERROR:root:[Errno 24] Too many open files: 'build/system/'
if not os.listdir(rootdir):
OSError: [Errno 24] Too many open files: 'build/system/'
Segmentation fault
LM10
  • 81
  • 6

0 Answers0