Bonjour,
Je voudrais savoir si un des dossiers de ce chemin est caché (peut importe lequel) : "D:/MonRepertoire/rep/test/MonFichier.txt"
Pour cela, je test si mon fichier est caché, si non je regarde si le répertoire père est caché, sinon je regarde si le répertoire père est caché... et ainsi de suite jusqu'à la racine. Voici mon code :Je ne vois pas d'ou vient l'erreur, en console ça boucle sur la racine :
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 public static boolean isPathHidden(Path path) { boolean bool = false; while (!path.equals(null) || bool==false){ System.out.println(path.toAbsolutePath()); if (path.toFile().isHidden()){ bool = true; } else { path = path.getParent(); } } return bool; } public static void main(String args[]) { Path path = Paths.get("D:\\MonRepertoire\\rep\\test\\MonFichier.txt"); if (isPathHidden (path)){ System.out.println(path.toAbsolutePath()+" a une repertoire caché dans son chemin"); } else { System.out.println(path.toAbsolutePath()+" ne contient aucun répertoire caché dans son chemin"); } }Quelqu'un voit ou est l'erreur ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 D:\MonRepertoire\rep\test\MonFichier.txt D:\MonRepertoire\rep\test D:\MonRepertoire\rep D:\MonRepertoire D:\ D:\ D:\ D:\ ...
Partager