Bonjour,

Je débute complètement en Python et malgré mes recherches sur le net je ne trouve pas de réponse. Je me tourne donc vers vous.

Je cherche a faire un gestionnaire de fichier 'minimaliste et portable' sous Linux/Tkinter avec deux listbox (une pour les dossiers et l'autre pour les fichiers). Je souhaite filtrer os.listdir pour exclure les fichiers cachés (.* sous Linux) et remplir mes listbox.
J'ai bien trouver comment filtrer sur les derniers caractères a la fin de l'item de la list mais rien a faire pour le premier caractère...

Donc mon problème c'est d'exclure les .* dans :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
listerep=[f for f in os.listdir(dirname) if os.path.isdir(os.path.join(dirname, f))]
listerep.sort()
listefich=[f for f in os.listdir(dirname) if os.path.isfile(os.path.join(dirname, f))]
listefich.sort()
 
for item in listerep:
    listrep.insert(END, item)
for item in listefich:
    listfich.insert(END, item)
Merci de m'aider a comprendre.

Bon, ok... Pas de honte puisque c'est mon premier jour (juste avec le net pour aide). Mon code pour vous faire rire :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os.path
import os
from Tkinter import *
 
dirname=os.environ['HOME']
rep_cour = os.getcwd()
 
class Application:
  def __init__(self, parent):
    self.myContainer1 = Frame(parent)
    self.myContainer1.pack()
 
    self.button1 = Button(self.myContainer1)
    self.button1["text"]= "Ouvrir"
    self.button1.pack(side=LEFT)
    self.button1.focus_force()
 
    self.button2 = Button(self.myContainer1)
    self.button2.configure(text="Renommer")  
    self.button2.pack(side=LEFT)
 
    self.button3 = Button(self.myContainer1)
    self.button3.configure(text="Sauvegarder")  
    self.button3.pack(side=LEFT)    
 
    self.button4 = Button(self.myContainer1)
    self.button4.configure(text="Supprimer")  
    self.button4.pack(side=LEFT)
 
    self.button5 = Button(self.myContainer1)
    self.button5.configure(text="Creer un repertoire")  
    self.button5.pack(side=LEFT)
 
    self.button6 = Button(self.myContainer1)
    self.button6.configure(text="Quitter", command=root.quit)  
    self.button6.pack(side=LEFT)  
 
    self.button7 = Button(self.myContainer1, text="Aide") 
    self.button7.pack(side=LEFT)
 
def callback():
    print "Retour"
 
root = Tk()
root.title('Gestionnaire de fichier')
root.geometry("715x400")
root.configure(bg="grey")
myapp = Application(root)
 
# frames
fmrep = Frame(root, width=360, height=350, bg="grey", relief=GROOVE)
fmfich = Frame(root, width=360, height=350, bg="grey", relief=GROOVE)
xfmrep = Frame(fmrep, width=300, height=260, relief=GROOVE, borderwidth=1)
xfmfich = Frame(fmfich, width=300, height=260, relief=GROOVE, borderwidth=1)
xfmrep.place(relx=0.01, rely=0.1, anchor=NW)
xfmfich.place(relx=0.01, rely=0.1, anchor=NW)
Label(fmrep, text='Dossiers').place(relx=.2, rely=0.1,anchor=W)
listrep = Listbox(xfmrep, height=17, width=45)
scrollrep = Scrollbar(xfmrep, command=listrep.yview)
Label(fmfich, text='Fichiers').place(relx=.2, rely=0.1,anchor=W)
listfich = Listbox(xfmfich, height=17, width=45)
scrollfich = Scrollbar(xfmfich, command=listfich.yview)
 
listrep.configure(yscrollcommand=scrollrep.set)
listfich.configure(yscrollcommand=scrollfich.set)
 
fmrep.pack(side=LEFT, expand=NO, fill=NONE)
listrep.pack(side=LEFT)
scrollrep.pack(side=RIGHT, fill=Y)
 
fmfich.pack(side=LEFT, expand=NO, fill=NONE)
listfich.pack(side=LEFT)
scrollfich.pack(side=RIGHT, fill=Y)
 
listerep=[f for f in os.listdir(dirname) if os.path.isdir(os.path.join(dirname, f))]
listerep.sort()
listefich=[f for f in os.listdir(dirname) if os.path.isfile(os.path.join(dirname, f))]
listefich.sort()
 
for item in listerep:
    listrep.insert(END, item)
for item in listefich:
    listfich.insert(END, item)
 
root.mainloop()