1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| import os
rep = os.path.join(os.path.expanduser('~'), 'Bureau')
# 'Bureau' pour moi > a remplacer par 'Desktop'.
# os.path.expanduser('~') pour le home de l'utilisateur : Universel.
for f in os.listdir(rep):
if os.path.splitext(f)[1].lower() == '.cfg':
# tutu.cfg > ('tutu', '.cfg')
# .lower() pour les minuscules
print(os.path.join(rep, f), 'yes')
# Vu que c'est pour un delete... os.path.join(rep, f) au cas ou...
# print() pour Python 3 > compatible 2.x.
else:
print(os.path.join(rep, f), 'non')
# Soit :
#for f in os.listdir(rep):
# if os.path.splitext(f)[1].lower() == '.cfg':
# os.remove(os.path.join(rep, f))
# Ou :
#for f in (f for f in os.listdir(rep) if os.path.splitext(f)[1].lower() == '.cfg'):
# os.remove(os.path.join(rep, f)) |