Skip to content

Instantly share code, notes, and snippets.

@panosl
Created August 3, 2018 12:11
Show Gist options
  • Save panosl/34ceba4228c111b9255ec6452d99cc48 to your computer and use it in GitHub Desktop.
Save panosl/34ceba4228c111b9255ec6452d99cc48 to your computer and use it in GitHub Desktop.
list all files in an active virtualenv or just your currently active path
#!/usr/bin/env python
import os, sys;
def better_listdir(dirpath):
"""
Generator yielding (filename, filepath) tuples for every
file in the given directory path.
"""
# First clean up dirpath to absolutize relative paths and
# symbolic path names (e.g. `.`, `..`, and `~`)
dirpath = os.path.abspath(os.path.expanduser(dirpath))
for filename in os.listdir(dirpath):
yield os.path.join(dirpath, filename)
files_path = [d for d in sys.path if os.path.isdir(d)]
files = [f for d in files_path for f in better_listdir(d) if os.path.isfile(f)]
print('\n'.join('{}'.format(f) for f in files))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment