From c6397e7db3ff68c9c197e1c23bfd8ee5d3730853 Mon Sep 17 00:00:00 2001 From: cirillom Date: Tue, 6 Dec 2022 15:16:33 -0300 Subject: [PATCH 1/2] Exercicio 01 concluido --- lista09/ex01ex02/pom.xml | 14 +++++ .../main/java/com/usp/ex01ex02/Ex01ex02.java | 62 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 lista09/ex01ex02/pom.xml create mode 100644 lista09/ex01ex02/src/main/java/com/usp/ex01ex02/Ex01ex02.java diff --git a/lista09/ex01ex02/pom.xml b/lista09/ex01ex02/pom.xml new file mode 100644 index 0000000..75c2b38 --- /dev/null +++ b/lista09/ex01ex02/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + com.usp + ex01ex02 + 1.0-SNAPSHOT + jar + + UTF-8 + 1.8 + 1.8 + com.usp.ex01ex02.Ex01ex02 + + \ No newline at end of file diff --git a/lista09/ex01ex02/src/main/java/com/usp/ex01ex02/Ex01ex02.java b/lista09/ex01ex02/src/main/java/com/usp/ex01ex02/Ex01ex02.java new file mode 100644 index 0000000..beed21e --- /dev/null +++ b/lista09/ex01ex02/src/main/java/com/usp/ex01ex02/Ex01ex02.java @@ -0,0 +1,62 @@ +package com.usp.ex01ex02; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; + +/** + * + * @author cillor + */ +public class Ex01ex02 { + + public static void main(String[] args) { + System.out.println("Scanning with no filter:"); + scanFiles("/home/cillor/OneDriv/Documentos/Comprovantes/BoletosAp"); + System.out.println("\n\n"); + System.out.println("Scanning with filter:"); + scanFilesType("/home/cillor/OneDriv/Documentos/Comprovantes/BoletosAp", ".pdf"); + } + + public static void scanFiles(String sAFilePath) { + File fonte = new File(sAFilePath); + if (fonte.isDirectory()) { + File[] files = fonte.listFiles(); + if (files != null) { + for (File file : files) { /* for(int i=0; i { + return name.toLowerCase().endsWith(type); + }; + + File fonte = new File(sAFilePath); + if (fonte.isDirectory()) { + File[] files = fonte.listFiles(textFilter); + if (files != null) { + for (File file : files) { /* for(int i=0; i Date: Tue, 6 Dec 2022 16:00:49 -0300 Subject: [PATCH 2/2] Ex02 concluido --- .gitignore | 1 + .../main/java/com/usp/ex01ex02/Ex01ex02.java | 51 +++++++++++-------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 5efbd95..05062ec 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ hs_err_pid* /lista07/EX01/build/ /lista06/ex05/dist/ /lista09/ex04/target/ +/lista09/ex01ex02/target/ diff --git a/lista09/ex01ex02/src/main/java/com/usp/ex01ex02/Ex01ex02.java b/lista09/ex01ex02/src/main/java/com/usp/ex01ex02/Ex01ex02.java index beed21e..19e16e6 100644 --- a/lista09/ex01ex02/src/main/java/com/usp/ex01ex02/Ex01ex02.java +++ b/lista09/ex01ex02/src/main/java/com/usp/ex01ex02/Ex01ex02.java @@ -11,19 +11,22 @@ public class Ex01ex02 { public static void main(String[] args) { + String path = "/home/cillor/OneDriv/Documentos/Comprovantes/BoletosAp"; + String filter = ".pdf"; + System.out.println("Scanning with no filter:"); - scanFiles("/home/cillor/OneDriv/Documentos/Comprovantes/BoletosAp"); - System.out.println("\n\n"); - System.out.println("Scanning with filter:"); - scanFilesType("/home/cillor/OneDriv/Documentos/Comprovantes/BoletosAp", ".pdf"); + scanFiles(path); + + System.out.println("\n\nScanning with filter:"); + scanFiles(path, filter); } - public static void scanFiles(String sAFilePath) { + static void scanFiles(String sAFilePath) { File fonte = new File(sAFilePath); if (fonte.isDirectory()) { File[] files = fonte.listFiles(); if (files != null) { - for (File file : files) { /* for(int i=0; i { - return name.toLowerCase().endsWith(type); - }; + static void scanFiles(String sAFilePath, String type) { File fonte = new File(sAFilePath); if (fonte.isDirectory()) { + + FilenameFilter textFilter = (File dir, String name) -> { + + String path = dir.getAbsolutePath() + "/" + name; + File file = new File(path); + if (file.isDirectory()) { + return true; //filtra dentro os diretorios, permitindo a recursão por todo mundo + } + + return name.toLowerCase().endsWith(type); //filtra fora os diretorios + }; + File[] files = fonte.listFiles(textFilter); - if (files != null) { - for (File file : files) { /* for(int i=0; i