Skip to content

Instantly share code, notes, and snippets.

@YannBouyeron
Last active January 11, 2018 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YannBouyeron/e9bbb3b3e33f5c10b94d3fb9f9ddc284 to your computer and use it in GitHub Desktop.
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
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