# Python fichier ? \[Résolut\]

**URL:** <https://www.debian-fr.org/t/python-fichier-resolut/15336>\
**Category:** Programmation\
**Created:** [Février 20, 2016, 6:06 UTC](https://www.debian-fr.org/t/python-fichier-resolut/15336 "2016-02-20T18:06:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![panthere](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/p/5daacb/32.png) [@panthere](https://www.debian-fr.org/u/panthere)\
**Post date:** [Février 20, 2016, 6:06 UTC](https://www.debian-fr.org/t/python-fichier-resolut/15336/1 "2016-02-20T18:06:28Z")

</div>

je voudrait scanner un répertoire & sous répertoire avec un filtre par extention.

voila ce que j’ai déja coder:

```auto
#!/usr/bin/env python
# -*- coding:Utf-8 -*- 
from os.path import join
import os
import string

def saveL(s):
  fic.write(s)
  fic.write('\n')  

def supprFile(s):
  os.remove(s)

def ListeFileExt(extSearch, rep, proc):
    for drive, dirs, files in os.walk(rep, 'topdown'):
        for name in files:
            filenu, ext = os.path.splitext(name)
            if (string.upper(ext) == string.upper(extSearch)):
                fich = os.path.join(drive, name)
                exec(proc + "('" + fich + "')")
if __name__ == ' __main__':

  # on peut lister tous les fichiers avec l'extension .mp3 dans un fichier texte
  fic = open('texte.txt','a')
  ListeFileExt('.mp3','/mp3','saveL')
  fic.close()

  # ou bien on peut demander de les supprimer
  #ListeFileExt('.net','C:\\','supprFile') 
```

l’erreur:

```auto
Traceback (most recent call last):
  File "/home/taz/Desktop/python/python_scan_rep.py", line 25, in <module>
    ListeFileExt('.mp3','/mp3','saveL')
  File "/home/taz/Desktop/python/python_scan_rep.py", line 20, in ListeFileExt
    exec(proc + "('" + fich + "')")
  File "<string>", line 1
    saveL('/mp3/Morricone cd 1 sure 2/16 - Il était une fois dans l'ouest As a judgment.mp3')
                                                                          ^
SyntaxError: invalid syntax
```

une idée ?

---

<div class="post-metadata">

**Author:** ![panthere](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/p/5daacb/32.png) [@panthere](https://www.debian-fr.org/u/panthere)\
**Post date:** [Février 20, 2016, 6:06 UTC](https://www.debian-fr.org/t/python-fichier-resolut/15336/2 "2016-02-20T18:06:29Z")

</div>

```auto
#!/usr/bin/env python
# -*- coding:Utf-8 -*- 
from os.path import join
import os
import string

def saveL(s):
  fic.write(s)
  fic.write('\n')  

def supprFile(s):
  os.remove(s)

def ListeFileExt(extSearch, rep, proc):
    for drive, dirs, files in os.walk(rep, 'topdown'):
        for name in files:
            filenu, ext = os.path.splitext(name)
            if (string.upper(ext) == string.upper(extSearch)):
                fich = os.path.join(drive, name)
                #xec(proc + "('" + fich + "')")
                exec ("%s ('%s')"%(proc,fich.replace("'","\\'")))
if __name__ == ' __main__':

  # on peut lister tous les fichiers avec l'extension .net dans un fichier texte
  fic = open('texte.txt','a')
  ListeFileExt('.mp3','/mp3','saveL')
  fic.close()

  # ou bien on peut demander de les supprimer
  #ListeFileExt('.net','C:\\','supprFile') 
```

les caractère grr ![](http://www.panthere-noire.com/image/smiley/104.gif)

---

<div class="post-metadata">

**Author:** ![mattotop](https://www.debian-fr.org/user_avatar/www.debian-fr.org/mattotop/32/3942_2.png) [@mattotop](https://www.debian-fr.org/u/mattotop)\
**Post date:** [Février 20, 2016, 6:06 UTC](https://www.debian-fr.org/t/python-fichier-resolut/15336/3 "2016-02-20T18:06:32Z")

</div>

ça serait pas un pb de syntaxe du genre  
ListeFileExt(’.mp3’,’/mp3’,‘saveL’)  
?

---

<div class="post-metadata">

**Author:** ![panthere](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/p/5daacb/32.png) [@panthere](https://www.debian-fr.org/u/panthere)\
**Post date:** [Février 20, 2016, 6:06 UTC](https://www.debian-fr.org/t/python-fichier-resolut/15336/4 "2016-02-20T18:06:45Z")

</div>

oui tout a fait , m’enfin j’ai plus ce souci 🙂
