Created
August 3, 2018 12:11
-
-
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
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
#!/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