0

I'm trying to list all sub-directories in the current working directory in a top-down list but my code lists all sub-directories, not just in the current working directory.

I tried doing this:

`

print("")
cwd1 = os.getcwd()
for subdir, dirs, files in os.walk(cwd1, topdown=True):
    for dir in dirs:
        print(dir)
print("")

`

This lists all sub-directories in every sub-directory, not just the current working directory. It gives the desired top-down effect but still has the problem above.

I've tried looking for an answer all over the internet but haven't found anything.

EDIT:

Like I've said, I've found no answers compatible with the output I desire (top-down). Most answers to questions like "How do I list sub-directories in Python?" have an output of ['exampledir', 'exampledir2'] but I'm trying to get

exampledir
exampledir2

A direct answer or a link to an answer would be greatly appreciated.

Musinks
  • 15
  • 4

0 Answers0