Skip to content

Instantly share code, notes, and snippets.

@gartenfeld
Created July 12, 2014 02:30
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 gartenfeld/3e3e04997b3c0202ad7b to your computer and use it in GitHub Desktop.
Save gartenfeld/3e3e04997b3c0202ad7b to your computer and use it in GitHub Desktop.
Load directory.
# Non-recursive
import os
def load_directory(data_path):
files_list = []
try:
for file_name in os.listdir(data_path):
if file_name.endswith(".html"):
files_list.append(file_name)
except IndexError:
sys.stderr.write( "Something went wrong with " + file_name + ".")
return files_list
# Recursive
from os import walk
def load_directory(data_path):
files_list = []
try:
for (dir_path, dir_names, file_names) in walk(data_path):
for file_name in file_names:
if file_name.endswith(".html"):
files_list.extend(file_name)
break
#Remove break for recursive.
except IndexError:
sys.stderr.write( "Something went wrong with " + filenames + ".")
return files_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment