-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from studas/lista09/ex01ex02
Lista09/ex01ex02
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,4 @@ hs_err_pid* | |
/lista07/EX01/build/ | ||
/lista06/ex05/dist/ | ||
/lista09/ex04/target/ | ||
/lista09/ex01ex02/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.usp</groupId> | ||
<artifactId>ex01ex02</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<exec.mainClass>com.usp.ex01ex02.Ex01ex02</exec.mainClass> | ||
</properties> | ||
</project> |
73 changes: 73 additions & 0 deletions
73
lista09/ex01ex02/src/main/java/com/usp/ex01ex02/Ex01ex02.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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) { | ||
String path = "/home/cillor/OneDriv/Documentos/Comprovantes/BoletosAp"; | ||
String filter = ".pdf"; | ||
|
||
System.out.println("Scanning with no filter:"); | ||
scanFiles(path); | ||
|
||
System.out.println("\n\nScanning with filter:"); | ||
scanFiles(path, filter); | ||
} | ||
|
||
static void scanFiles(String sAFilePath) { | ||
File fonte = new File(sAFilePath); | ||
if (fonte.isDirectory()) { | ||
File[] files = fonte.listFiles(); | ||
if (files != null) { | ||
for (File file : files) { | ||
try { | ||
if (file.isDirectory()) | ||
scanFiles(file.getCanonicalPath()); | ||
else | ||
System.out.println(file.getName()); | ||
} catch (IOException ex) { | ||
System.out.println("Erro:" + ex.getMessage()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
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); | ||
|
||
for (File file : files) { | ||
try { | ||
if (file.isDirectory()) | ||
scanFiles(file.getCanonicalPath(), type); | ||
else | ||
System.out.println(file.getName()); | ||
} catch (IOException ex) { | ||
System.out.println("Erro:" + ex.getMessage()); | ||
} | ||
} | ||
} | ||
} | ||
} |