LinkedNestBlog

특정 디렉토리 내 파일 목록을 조회하려면

by jinwon lee



특정 디렉토리 내 파일 목록을 조회하려면

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
String targetPath = "C:/testFolder/";
File dir = new File(targetPath);
 
dir.exists()              // 디렉토리가 존재하는가?
dir.isDirectory()       // dir은 디렉토리인가?  
 
String[] fileNames = dir.list(new FilenameFilter(){            
 
    public boolean accept(File d, String fName){                      
        if(fName.indexOf(".jpg")!=-1) 
            return true;     // ".jpg"확장자의 파일이 있으면 true                      
        else 
            return false;    // 없으면 false 값 return.             
    }
}); 
 
for(int i=0;i<fileNames.length;i++){
    // 파일명을 확인할 수 있다.
}
cs 

 
Ref. URL : http://scarlett.tistory.com/entry/%EC%9E%90%EB%B0%94%EA%B3%B5%EB%B6%80-1%EC%9E%85%EC%B6%9C%EB%A0%A5IO-%EA%B0%9C%EC%9A%94