Skip to content

Instantly share code, notes, and snippets.

@nimpy
Last active February 21, 2022 13:30
Show Gist options
  • Save nimpy/1f7275d0d544b3a26fa2aa976b4675ff to your computer and use it in GitHub Desktop.
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
# 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