Skip to content

Instantly share code, notes, and snippets.

@danielthiel
Created May 3, 2014 16:10
Show Gist options
  • Save danielthiel/4eded2f1ee977fb1aca6 to your computer and use it in GitHub Desktop.
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
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