Created
August 17, 2015 11:44
-
-
Save hkraji/4ad56882748a0c216613 to your computer and use it in GitHub Desktop.
Za Kerima
This file contains hidden or 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
import java.io.File; | |
import java.io.FileFilter; | |
public class Main { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
System.out.println(searchFile("test.pp", new File("/Users/haris/r8"))); | |
} | |
public static String searchFile(String fileName, File root) { | |
String path = null; | |
if (root.isDirectory() && !root.isHidden()) { | |
File[] files = root.listFiles(new FileFilter() { | |
@Override | |
public boolean accept(File file) { | |
return !file.isHidden() && file.isFile(); | |
} | |
}); | |
File[] directories = root.listFiles(new FileFilter() { | |
@Override | |
public boolean accept(File file) { | |
return !file.isHidden() && file.isDirectory(); | |
} | |
}); | |
for (File f : files) { | |
if (f.getName().equals(fileName)) { | |
path = f.getAbsolutePath(); | |
return path; | |
} | |
} | |
for (File dir : directories) { | |
path = searchFile(fileName, dir); | |
if (path != null) { | |
return path; | |
} | |
} | |
return null; | |
} else if (root.isFile() && root.getName().equals(fileName)) { | |
path = root.getAbsolutePath(); | |
return path; | |
} | |
return "No such file on clients computer"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment