특정 디렉토리 내 파일 목록을 조회하려면
특정 디렉토리 내 파일 목록을 조회하려면
|
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 |