Created
September 13, 2017 08:31
-
-
Save Fundibalus/4e02cb82f64597db0bf9acfa7be50000 to your computer and use it in GitHub Desktop.
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package dateifinden; | |
import java.io.File; | |
import java.io.IOException; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
/** | |
* | |
* @author B201 | |
*/ | |
public class DateiFinden { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) { | |
File f = new File("C:\\Intel"); | |
System.out.print(dateisuchen(f, "intel.txt")); | |
} | |
public static String dateisuchen(File dir, String dateiname) { | |
String endpath = ""; | |
File[] files = dir.listFiles(); | |
//boolean gefunden = false; | |
if (files != null) { // Erforderliche Berechtigungen etc. sind vorhanden | |
for (File file : files) { | |
if (file.isDirectory()) { | |
try { | |
endpath = dateisuchen(new File(file.getCanonicalPath()), dateiname); | |
} catch (IOException ex) { | |
Logger.getLogger(DateiFinden.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
if(!"".equals(endpath)) { | |
break; | |
} | |
} else { | |
if (file.getName().equals(dateiname)) { | |
try { | |
return file.getCanonicalPath() + ""; | |
} catch (IOException ex) { | |
Logger.getLogger(DateiFinden.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} | |
} | |
} | |
} | |
return endpath; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment