Last active
January 11, 2018 08:47
-
-
Save YannBouyeron/e9bbb3b3e33f5c10b94d3fb9f9ddc284 to your computer and use it in GitHub Desktop.
Liste récursive des fichiers et dossiers d’un répertoire - alternative à glob.glob pour python < 3.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import fnmatch | |
import sys | |
def recurlist(path): | |
""" | |
path est une chaine de caractere | |
retourne une liste recursive des dossiers et fichiers contenus dans path. | |
c'est une alternative a glob.glob('**',recursive=True) qui ne fonctionne pas en python < 3.5""" | |
r = [] | |
for root, dir, files in os.walk(path): | |
if root != path: | |
r.append(root.replace(path+'/', '')) | |
for f in fnmatch.filter(files, "*"): | |
x = root+'/'+f | |
r.append(x) | |
return r | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment