Reputation: 110093
Is there a method to find all directories in a given directory? I am trying the following, which gives me an empty list:
[item for item in os.listdir(dir) if os.path.isdir(item)]
Upvotes: 0
Views: 215
Reputation: 798456
You forgot to use os.path.join()
to join the directory to the entries.
Upvotes: 3
Reputation: 9492
os.listdir(dir)
returns names relative to dir
, you have to do something like:
[item for item in os.listdir(dir) if os.path.isdir(os.path.join(dir, item))]
Upvotes: 4