Created
July 15, 2015 13:54
-
-
Save hellpanderrr/4ecf37745273df374a56 to your computer and use it in GitHub Desktop.
python get files in a folder
This file contains 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
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