2 Upvotes

Get Immediate Subdirectories Using Python

Python
General Python

Returns a list containing the folder names of all immediate subdirectories below the current working directory.

import os
os.chdir(r'D:/Main/')
sub_dir = next(os.walk('.'))[1]

By GregHe1979 - Last Updated Sept. 8, 2021, 10:15 p.m.

Did you find this snippet useful?

Sign up to bookmark this in your snippet library

COMMENTS
RELATED SNIPPETS
Python For Else Loop
Python
General Python

Loop

2
Top Contributors
103
100