Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Main { private static List<String> getSortedGPXFilenames(File dir, String sub) { final List<String> list = new ArrayList<String>(); readGpxDirectory(dir, list, ""); Collections.sort(list, new Comparator<String>() { @Override public int compare(String object1, String object2) { if (object1.compareTo(object2) > 0) { return -1; } else if (object1.equals(object2)) { return 0; } return 1; } }); return list; } private static List<String> getSortedGPXFilenames(File dir) { return getSortedGPXFilenames(dir, null); } private static void readGpxDirectory(File dir, final List<String> list, String parent) { if (dir != null && dir.canRead()) { File[] files = dir.listFiles(); if (files != null) { for (File f : files) { if (f.getName().toLowerCase().endsWith(".gpx")) { //$NON-NLS-1$ list.add(parent + f.getName()); } else if (f.isDirectory()) { readGpxDirectory(f, list, parent + f.getName() + "/"); } } } } } }