Skip to content

Instantly share code, notes, and snippets.

@dineshviswanath
Created September 19, 2013 20:29
Show Gist options
  • Save dineshviswanath/6629393 to your computer and use it in GitHub Desktop.
Save dineshviswanath/6629393 to your computer and use it in GitHub Desktop.
Code to identify whether file or directory
public class RecFind {
public static void main(String a[]) throws FileNotFoundException, IOException{
String target = a[0];
String[] tmp;
//Extra File logging. Not required for File or Dir
FileOutputStream fos = new FileOutputStream("Recfind.log",true);
fos.write("Program Started".getBytes());
System.setOut((java.io.PrintStream)fos);
if("".equals(target)) throw new IllegalArgumentException("Please provide file name to find");
File targetFile= new File(target);
String[] files = targetFile.list();
System.out.println("Number of Files present in this directory -> "+files.length);
System.out.println("Files -> ");
for(int i=0;i<files.length;i++){
tmp = new File(files[i]).list();
System.out.println(files[i]+((tmp==null)? " is a file" : " is a directory "));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment