Skip to content

Instantly share code, notes, and snippets.

@hellpanderrr
Created July 15, 2015 13:54
Show Gist options
  • Save hellpanderrr/4ecf37745273df374a56 to your computer and use it in GitHub Desktop.
Save hellpanderrr/4ecf37745273df374a56 to your computer and use it in GitHub Desktop.
python get files in a folder
def get_filelist(path, extension=None,only_folders=False):
'''Returns list of files in a given folder, without going further
Parameters
---------
extension: Collect only files with this extension
only_folders: Collect only folders names
'''
filenames = []
if not only_folders:
for i in os.walk(path).next()[2]:
if (extension):
if os.path.splitext(i)[1] == extension :
filenames.append(os.path.join(path,i))
else:
filenames.append(os.path.join(path,i))
else:
for i in os.walk(path).next()[1]:
filenames.append(os.path.join(path,i))
return filenames
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment