Simple exemple sur comment obtenir le nom d'un fichier et son extension à partir d'un chemin d'accès sous python (ici 'users/toto/desktop/file.pdf')
>>> import os>>> path = 'users/toto/desktop/file.pdf'>>> from os.path import basename>>> basename(path)'file.pdf'>>> fileName, fileExtension = os.path.splitext(path)>>> fileExtension'.pdf'
Recherches associées
| Liens | Site |
|---|---|
| How to get the filename without the extension from a path in Python? | stackoverflow |
| Extracting extension from filename in Python | stackoverflow |
