Friday, 6 January 2012

java program to print-sub-files-and-sub-directories-in-a-directory

package com.usr.files;

import java.io.File;

public class ListFiles {
     public static void main(String[] args) {
           File rootDir=new File("E:\\songs");
           listAllFiles(rootDir);
     }

     private static void listAllFiles(File file) {
           if(file.isDirectory()){
                System.out.println("Directory Name is:"+file.getName());
                for(int i=0;i<file.listFiles().length;i++){
                     listAllFiles(file.listFiles()[i]);
                }
                System.out.println("File Name is:"+file.getName());
           }

     }
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.