Avec os.listdir() on peut obtenir tout ce qui se trouve dans un répertoire, répertoires et fichiers.
Utilisation :
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
Ou vous pouvez utiliser os.walk()
qui donne deux listes pour chaque répertoire qu'il visite - division en fichiers et répertoires.
Utilisation :
from os import walk
f = []
for (dirpath, dirnames, filenames) in walk(mypath):
f.extend(filenames)