|
Here
is a program that I used to printing names of all the files in a
directory.
import
java.io.*;
public class DirectoryParser { public static void main(String args[]) { if(args.length <= 0) { System.out.println("Usage java DirectoryParser <name of the directory>"); System.exit(1); } File fd0 = new
File(args[0]);
if(!fd0.exists()) { System.out.println("Directory does not exist"); System.exit(2); } if(fd0.isDirectory() ==
false)
{ System.out.println("The specified path is not a directory"); System.exit(3); }
System.out.println("Directory Exists");
// Parse that directory parseDirectory(args[0]); } public static void parseDirectory(String
strFileName)
{ File fd = new File(strFileName); String strFileNameList[] = fd.list(); for(int i=0;i<strFileNameList.length;i++) { File fCurrent = new File(strFileName+"/"+strFileNameList[i]); if(fCurrent.isDirectory() == true) { System.out.println("Directory"+strFileNameList[i]); parseDirectory(fCurrent.getAbsolutePath()); } else { System.out.println("File Name "+strFileNameList[i]+ " Directory Name "+fd.getName()); } } } } Jeetendra Dassani
|
- does anyone how to list all files in the specific directory... chenghong
- Re: does anyone how to list all files in the specific ... Nicolas Thiery
- Re: does anyone how to list all files in the specific ... Arun
- Re: does anyone how to list all files in the specific ... Jeetendra
- Re: does anyone how to list all files in the specific ... chenghong
- Re: does anyone how to list all files in the specific ... Mark Galbreath
