Created
July 12, 2014 02:30
-
-
Save gartenfeld/3e3e04997b3c0202ad7b to your computer and use it in GitHub Desktop.
Load 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
# 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