Skip to content

Instantly share code, notes, and snippets.

@higarin
Created November 19, 2015 01:54
Show Gist options
  • Save higarin/d169937bf652facefe6e to your computer and use it in GitHub Desktop.
Save higarin/d169937bf652facefe6e to your computer and use it in GitHub Desktop.
Make FIle List
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
public class FileManager {
public static List<File> getParseFileList(String path){
List<File> fileList = new ArrayList<File>();
File dir = new File(path);
fileList = makeFilelist(dir);
File[] copyList = fileList.toArray(new File[0]);
Arrays.sort(copyList, new FileSort());
fileList = Arrays.asList(copyList);
return fileList;
}
private static List<File> makeFilelist(File root){
List<File> list = new ArrayList<File>();
for(File file : root.listFiles()){
if(file.isDirectory()){
list.addAll(makeFilelist(file));
}else{
if(file.getName().indexOf(".csv") > 0){
list.add(file);
}
}
}
return list;
}
private static class FileSort implements Comparator<File>{
public int compare(File src, File target){
int diff = src.getName().compareTo(target.getName());
return diff;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment