Skip to content

Commit febf4e0

Browse files
committed
directory loop
1 parent b5bf5d5 commit febf4e0

File tree

4 files changed

+60
-34
lines changed

4 files changed

+60
-34
lines changed

rkaScanSupport/src/main/java/scanning/LookupWords.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ private static List<LookupWordsTO> convertJsonToJavaBeanTestDataTO(String jsonSt
5151

5252
private static String getFile() throws IOException {
5353
logger.info("");
54-
// TODO auf h:
55-
// Scanner in = new Scanner(new FileReader("/home/rk/IntelliJ-Workspace/rkaScanSupport/src/main/resources/LookupWords.json"));
56-
Scanner in = new Scanner(new FileReader("H:\\Dropbox\\Scan_Source\\LookupWords.json"));
54+
// Scanner in = new Scanner(new FileReader("H:\\Dropbox\\Scan_Source\\LookupWords.json"));
55+
Scanner in = new Scanner(new FileReader("/home/rk/Dropbox/Scan_Source/LookupWords.json"));
5756
StringBuilder sb = new StringBuilder();
5857
while(in.hasNext()) {
5958
sb.append(in.next());

rkaScanSupport/src/main/java/scanning/Main.java

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import java.io.File;
77
import java.io.IOException;
8-
import java.nio.file.Path;
98
import java.util.List;
109

1110
public class Main {
@@ -17,30 +16,53 @@ public class Main {
1716

1817
public static void main(String[] args) throws IOException {
1918

20-
String filename = "H:\\Dropbox\\___temp_SCAN\\Ohne Titel_b.pdf"; // TODO LOOP, alles ohne *_PDF.pdf
19+
// String filename = "H:\\Dropbox\\___temp_SCAN\\Ohne Titel_b.pdf"; // TODO LOOP, alles ohne *_PDF.pdf
20+
// String filename = "/home/rk/Dropbox/___temp_SCAN/Ohne Titel_b.pdf"; // TODO LOOP, alles ohne *_PDF.pdf
2121

22-
PdfDatei pdfDatei = new PdfDatei(filename);
22+
File[] files = new File("/home/rk/Dropbox/___temp_SCAN/").listFiles();
23+
for (File file : files) {
24+
if (file.isDirectory()) {
25+
logger.debug("Directory: " + file.getName());
26+
} else {
27+
System.out.println("File: " + file.getName());
28+
bearbeiteDatei(file); // Calls same method again.
29+
}
30+
}
31+
32+
33+
34+
35+
}
36+
37+
private static void bearbeiteDatei(File file) throws IOException {
38+
logger.debug("File: " + file.getAbsolutePath());
39+
PdfDatei pdfDatei = new PdfDatei(file.getAbsolutePath());
2340
Scanning s = new Scanning();
2441

42+
String newFileNamePartByDateLookup = null;
43+
newFileNamePartByDateLookup = s.getFileNamePartByDateLookup(pdfDatei.getPdfText());
44+
logger.info("newFileNamePartByDateLookup: " +newFileNamePartByDateLookup);
45+
2546
String newFileNamePartByWordLookupMatch = null;
2647
try {
2748
newFileNamePartByWordLookupMatch = s.getFileNamePartByWordLookupMatch(pdfDatei.getWortListe(), LOOKUP_WORDS_LIST);
2849
logger.info("newFileNamePartByWordLookupMatch: " +newFileNamePartByWordLookupMatch);
50+
51+
//*******************************
52+
// RENAME
53+
//*******************************
54+
String newFilename = newFileNamePartByDateLookup + "_" +newFileNamePartByWordLookupMatch +"_PDF.pdf";
55+
logger.info("-------------------------------------");
56+
logger.info("NEW FILENAME: " +newFilename);
57+
logger.info("-------------------------------------");
58+
String path = file.getPath(); //new File(filename).getParent();
59+
System.out.println("path "+ path);
60+
//s.renameFile(filename,path+"/"+newFilename); // TODO
61+
2962
} catch (NoMatchingLookupWordsException e) {
3063
logger.info("newFileNamePartByWordLookupMatch No Matchup");
3164
}
3265

33-
String newFileNamePartByDateLookup = null;
34-
newFileNamePartByDateLookup = s.getFileNamePartByDateLookup(pdfDatei.getPdfText());
35-
logger.info("newFileNamePartByDateLookup: " +newFileNamePartByDateLookup);
36-
37-
String newFilename = newFileNamePartByDateLookup + "_" +newFileNamePartByWordLookupMatch +"_PDF.pdf";
38-
logger.info("NEW FILENAME: " +newFilename);
39-
40-
String path = new File(filename).getParent();
41-
//System.out.println("path "+ path);
42-
//s.renameFile(filename,path+"/"+newFilename);
43-
4466
}
4567

4668
}

rkaScanSupport/src/main/java/scanning/ReadPdfAndLookupInDictionary.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public void start() throws IOException {
2020
List<String> pdfWordList = new ArrayList<String>();
2121

2222

23-
//try (PDDocument document = PDDocument.load(new File("/home/rk/Dropbox/___temp_SCAN/Ohne Titel_b.pdf"))) {
24-
try (PDDocument document = PDDocument.load(new File("H:\\Dropbox\\___temp_SCAN\\Ohne Titel_b.pdf"))) {
23+
try (PDDocument document = PDDocument.load(new File("/home/rk/Dropbox/___temp_SCAN/Ohne Titel_b.pdf"))) {
24+
//try (PDDocument document = PDDocument.load(new File("H:\\Dropbox\\___temp_SCAN\\Ohne Titel_b.pdf"))) {
2525

2626
document.getClass();
2727

rkaScanSupport/src/main/java/scanning/Scanning.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
import java.nio.file.Files;
88
import java.nio.file.Path;
99
import java.nio.file.Paths;
10-
1110
import java.nio.file.StandardCopyOption;
1211
import java.time.LocalDate;
1312
import java.time.format.DateTimeFormatter;
1413
import java.time.format.DateTimeParseException;
15-
import java.time.format.FormatStyle;
16-
import java.util.*;
14+
import java.util.ArrayList;
15+
import java.util.Collections;
16+
import java.util.List;
17+
import java.util.ListIterator;
1718

1819
public class Scanning {
1920

@@ -39,7 +40,7 @@ public String getFileNamePartByDateLookup(String pdfText) {
3940
try {
4041
return getRelevantDateFromString(pdfText);
4142
} catch (Exception e) {
42-
e.printStackTrace();
43+
// e.printStackTrace();
4344
return "XXXX_XX_XX";
4445
}
4546
}
@@ -66,20 +67,24 @@ public String getRelevantDateFromString(String input) {
6667
}
6768
//Collections.sort(dates, Collections.reverseOrder());
6869
LocalDate xmin = LocalDate.parse("2010-01-01"); //default, ISO_LOCAL_DATE
69-
logger.debug("XMIN: " +xmin);
70-
// for (LocalDate d : dates){
71-
// if (d.isBefore(xmin))
72-
// dates.remove(d);
73-
// }
74-
for(int i=0;i<dates.size();i++) {
75-
logger.debug(String.valueOf(dates.get(i)));
76-
if (dates.get(i).isBefore(xmin))
77-
dates.remove(i); // TODO hier weiter
70+
//logger.debug("XMIN: " +xmin);
71+
//logger.debug("Anzahl Datum: " +dates.size());
72+
for (ListIterator<LocalDate> iter = dates.listIterator(); iter.hasNext(); ) {
73+
LocalDate datum = iter.next();
74+
if (datum.isBefore(xmin)) {
75+
logger.debug("delete");
76+
iter.remove();
77+
}
7878
}
79+
//logger.debug("Anzahl Datum: " +dates.size());
7980
Collections.sort(dates);
8081
//System.out.println(dates);
81-
//System.out.println(dates.get(0));
82-
return String.valueOf(dates.get(0)).replace("-","_");
82+
if (dates.size() >0) {
83+
System.out.println(dates.get(0));
84+
return String.valueOf(dates.get(0)).replace("-", "_");
85+
} else {
86+
return null;
87+
}
8388
}
8489

8590
public void renameFile(String oldNameAndPath, String newNameAndPath) {

0 commit comments

Comments
 (0)