Created
May 3, 2014 16:10
-
-
Save danielthiel/4eded2f1ee977fb1aca6 to your computer and use it in GitHub Desktop.
different walk stuff in python, go through all files recursively or just files in one directory
This file contains hidden or 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
import os | |
def all_files(dirname): | |
for root, dirs, filenames in os.walk(dirname): | |
for f in filenames: | |
print f | |
# log = open(os.path.join(root, f),'r') | |
def all_files_in_dir(dirname): | |
onlyfiles = [ f for f in os.listdir(dirname) if os.path.isfile(os.path.join(dirname,f)) ] | |
for f in onlyfiles: | |
absolute_path_of_file = os.path.join(dirname, f) | |
print absolute_path_of_file | |
if __name__ == '__main__': | |
current_dir = os.path.dirname(os.path.abspath(__file__)) | |
all_files(current_dir) | |
all_files_in_dir(current_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment