python:programmes:find
                Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| python:programmes:find [2019/07/28 17:25] – [os.scandir] root | python:programmes:find [2019/07/29 17:27] (Version actuelle) – [os.scandir] root | ||
|---|---|---|---|
| Ligne 26: | Ligne 26: | ||
| ===== os.scandir ===== | ===== os.scandir ===== | ||
| - | C'est la méthode la plus performante en rapidité et en souplesse de code: | + | C'est la méthode la plus performante | 
| + | Exemple pour trouver les fichiers **suid** d'un répertoire avec **crossmount** activé ou désactivé (option **xdev** de la commande **find**) : | ||
| <code python find.py> | <code python find.py> | ||
| - | def find(root): | + | def find(path, crossmount=True): | 
| + | dev = os.stat(path).st_dev | ||
| try: | try: | ||
| - | for entry in os.scandir(root): | + | for entry in os.scandir(path): | 
| if entry.is_dir() and not entry.is_symlink(): | if entry.is_dir() and not entry.is_symlink(): | ||
| - | for result in find2(entry.path): | + |  | 
| + | continue | ||
| + |  | ||
| yield result | yield result | ||
| yield entry | yield entry | ||
| Ligne 42: | Ligne 46: | ||
| # Search suid files | # Search suid files | ||
| - | { print(f.path) for f in find('/ | + | for suid in (f.path for f in find('/ | 
| + | print(suid) | ||
| </ | </ | ||
| Ligne 61: | Ligne 66: | ||
| - | ===== os.scandir | + | ===== os.listdir | 
| C'est la méthode la moins performante: | C'est la méthode la moins performante: | ||
| Ligne 78: | Ligne 83: | ||
| print(e, file=sys.stderr) | print(e, file=sys.stderr) | ||
| </ | </ | ||
| + | |||
| + | ===== faster-than-walk ===== | ||
| + | C'est un module externe [[https:// | ||
python/programmes/find.1564334700.txt.gz · Dernière modification :  de root
                
                