55
66import java .io .File ;
77import java .io .IOException ;
8- import java .nio .file .Path ;
98import java .util .List ;
109
1110public 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}
0 commit comments