Last active
February 21, 2022 13:30
-
-
Save nimpy/1f7275d0d544b3a26fa2aa976b4675ff to your computer and use it in GitHub Desktop.
Print the names of all sub-directories for the current directory in sorted alphabetical order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# credit: https://stackoverflow.com/a/44228436/4031135 | |
from pathlib import Path | |
p = Path('.') | |
# all subdirectories in the current directory, not recursive | |
list_subdirs = [f.name for f in p.iterdir() if f.is_dir()] | |
list_subdirs.sort() | |
for subdir in list_subdirs: | |
print(subdir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment