Skip to content

Instantly share code, notes, and snippets.

@hkraji
Created August 17, 2015 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkraji/4ad56882748a0c216613 to your computer and use it in GitHub Desktop.
Save hkraji/4ad56882748a0c216613 to your computer and use it in GitHub Desktop.
Za Kerima
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