Skip to content

Instantly share code, notes, and snippets.

@nimpy
Created February 21, 2022 13:30
Show Gist options
  • Save nimpy/92725af4c81e0c2ae1da09cf0b1b7d17 to your computer and use it in GitHub Desktop.
Save nimpy/92725af4c81e0c2ae1da09cf0b1b7d17 to your computer and use it in GitHub Desktop.
Print the names of all sub-directories for the current directory in reversely 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 = sorted(list_subdirs, reverse=True)
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