Skip to content

Instantly share code, notes, and snippets.

@NicholasMurray
Created March 20, 2017 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NicholasMurray/6bb369f67dd16f9ce81314b7f602fe68 to your computer and use it in GitHub Desktop.
Save NicholasMurray/6bb369f67dd16f9ce81314b7f602fe68 to your computer and use it in GitHub Desktop.
Find subdirectories in python
import os
import sys
walk_dir = 'directory_parent'
# If your current working directory may change during script execution, it's recommended to
# immediately convert program arguments to an absolute path. Then the variable root below will
# be an absolute path as well. Example:
# walk_dir = os.path.abspath(walk_dir)
print('walk_dir (absolute) = ' + os.path.abspath(walk_dir))
for root, subdirs, files in os.walk(walk_dir):
print('--\nroot = ' + root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment