From 0c9618880b910b64144e2b34f03929a883f14204 Mon Sep 17 00:00:00 2001 From: Baptiste Royer <baptiste.royer.etu@univ-lille.fr> Date: Tue, 21 May 2024 11:58:48 +0200 Subject: [PATCH] ajout du tp 09 --- src/tp09/ListExecutable.java | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/tp09/ListExecutable.java diff --git a/src/tp09/ListExecutable.java b/src/tp09/ListExecutable.java new file mode 100644 index 0000000..c07e641 --- /dev/null +++ b/src/tp09/ListExecutable.java @@ -0,0 +1,37 @@ +package tp09; + +import java.io.File; +import java.util.Scanner; + +public class ListExecutable { + public static void printExecutable(File file) { + if (file.exists()) { + if(file.isFile() && !file.isHidden()) { + if(file.canExecute()) { + System.out.println(file.getName()); + } else { + System.out.println("Nothing is executable."); + } + } else { + File[] li = file.listFiles(); + for (File fichier : li) { + if(fichier.isFile() && !file.isHidden()) { + if(fichier.canExecute()) { + System.out.println(fichier.getName()); + } + } + } + } + } else { + System.out.println("File does not exist."); + } + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.print("Veuillez entrer le nom du fichier ou du dossier que vous souhaitez vérifier : "); + File file = new File(scanner.nextLine()); + printExecutable(file); + scanner.close(); + } +} \ No newline at end of file -- GitLab