I would like to handle (read, do something to) each file but I need to do this in order of the after the ~. So I want to sort the files on the number that appears in the filename.
Any ideas..?
Thanks
AcidHawk
06-02-2004, 08:12 AM
AcidHawk
Idea
I've come up with the following..
public String FirstFile(String dirname) {
String filename;
File dir = new File(dirname);
String[] children = dir.list();
Arrays.sort(children);
if (children == null) {
// Either dir does not exist or is not a directory
filename = null;
} else {
filename = children[0];
}
return filename;
}
Any comments..?
06-02-2004, 11:59 AM
mikeBarr81
i think the problem is that is that the sort() method sorts the elements based on their compareTo() methods. The compareTo() of String won't work in the way that you want. It won't ignore whatever comes before the ~
If the names of the files before the ~ are not all identicle then it won't sort them by the number. You'll have to extract the number from the string using something like the split() method of string.
06-02-2004, 12:00 PM
mikeBarr81
i think the problem is that is that the sort() method sorts the elements based on their compareTo() methods. The compareTo() of String won't work in the way that you want. It won't ignore whatever comes before the ~
If the names of the files before the ~ are not all identicle then it won't sort them by the number. You'll have to extract the number from the string using something like the split() method of string.