If you want to filter the directories then:
os.listdir() —> will return the list of all names in a given path.
You can use os.path.isdir() for this:
basic_path = ‘/path/to/directory’
for name in os.listdir(basic_path):
paths = os.path.join(basic_path, name)
if os.path.isdir(paths):
# skip directories
continue
os.walk()–> this function does the same work under the hood and unless you want to recurse down subdirectories