basepath = '/path/to/directory'
for fname in os.listdir(basepath):
    path = os.path.join(basepath, fname)
if os.path.isdir(path):
    pass
Python - how to find files and skip directories in os.listdir