Created
September 19, 2013 20:29
-
-
Save dineshviswanath/6629393 to your computer and use it in GitHub Desktop.
Code to identify whether file or directory
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
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