import java.io.File;

public class test01 {
	
	public static void main(String[] args) {
		try {			
			String path = "C:\\tools\\Java\\workspace\\test001";//System.getProperty("user.dir");
			
			(new test01()).showFileList(path);

		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

	public void showFileList(String path) throws Exception {
		File dir = new File(path);
		File[] files = dir.listFiles();
		
		int fileCnt = 0;		
		int dirCnt = 0;
	
		for (int i = 0; i < files.length; i++) {
			File file = files[i];

			if (file.isFile()) {
				fileCnt++;// 파일 개수 				
				//System.out.println("[File]" + file.getCanonicalPath().toString());				
				//System.out.println("[Directory CNT]" + file.getCanonicalPath().toString()+"  " +fileCnt);
				
			} else if (file.isDirectory()) {
				dirCnt++;
				//System.out.println("[Directory]" + file.getCanonicalPath().toString());
				try {
					showFileList(file.getCanonicalPath().toString());
				} catch (Exception e) {
				}
			}
		}		
		System.out.println(dir.getCanonicalPath().toString()+"  file :"+fileCnt+"  dirCnt:"+dirCnt);
	}

}
반응형