This is a Python Code Snippet that will return a list of files based on extension from a directory including full path.
#Usage yourlist = return_file_list_by_ext("directory",".ext")
def return_file_list_by_ext(directory,ext):
import os
file_list = []
for file in os.listdir(directory):
if file.endswith(ext):
# Store the Full Path
file_list.append(os.path.join(directory, file))
return file_list
Usage yourfilelist = return_file_list_by_ext(r”E:\Root\Corpus\Text\Cleaning\\”,”.txt”)
The command above will return in a list – the full path including filename in directory E:\Root\Corpus\Text\Cleaning\ that end with .txt.
Have a Project or Idea!?
I am Available for Freelance Projects
My skills are always primed and ready for new opportunities to be put to work, and I am ever on the lookout to connect with individuals who share a similar mindset.
If you’re intrigued and wish to collaborate, connect, or simply indulge in a stimulating conversation, don’t hesitate! Drop me an email and let’s begin our journey. I eagerly anticipate our interaction!