Skip to content

Instantly share code, notes, and snippets.

Created September 19, 2013 20:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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());
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