-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepertoire.java
More file actions
50 lines (38 loc) · 888 Bytes
/
Repertoire.java
File metadata and controls
50 lines (38 loc) · 888 Bytes
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
package scandir;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Repertoire extends Noeud {
private List<Noeud> enfants;
public Repertoire(File nom) {
super(nom);
enfants = new ArrayList<Noeud>();
getEnfants();
}
private void getEnfants() {
Noeud noeud;
for (File file : nom.listFiles()) {
if (file.isDirectory()) {
noeud = new Repertoire(file);
}
else {
noeud = new Fichier(file);
}
enfants.add(noeud);
}
}
public String toString() {
StringBuffer sb = new StringBuffer();;
Iterator<Noeud> i = enfants.iterator();
// ajouter le nom du répertoire
sb.append(addSpace() + "R: " + nom.toString() + "\n");
niveau++;
// ajouter le nom des enfants
while (i.hasNext()) {
sb.append(i.next().toString());
}
niveau--;
return sb.toString();
}
}