sort memo(windowsXp )

import java.io.File;
import java.util.Arrays;
import java.util.Comparator;

public class folderSorts {

/**
* @param args
*/
public static void main(String args) {
// TODO 自動生成されたメソッド・スタブ


String path = "C:/test";
File dir = new File(path);

File files = dir.listFiles();

class FileSort implements Comparator{

public int compare(File lh, File rh){


Integer iL = Integer.parseInt(lh.getName().replaceAll("[^0-9]",""));
Integer iR = Integer.parseInt(rh.getName().replaceAll("[^0-9]",""));



StringBuffer iLb = new StringBuffer(iL.toString());
StringBuffer iRb = new StringBuffer(iR.toString());
int Padcount = iLb.length() - iRb.length();

StringBuffer wStr = new StringBuffer();

if(Padcount>0){

for (int i = 0; i < Padcount; i++) {

wStr.append("0");
}
wStr.append(iRb);//前ゼロパディング
iRb = wStr;

}else if(Padcount<0){

Padcount=Math.abs(Padcount);
for (int i = 0; i < Padcount; i++) {

wStr.append("0");
}
wStr.append(iLb);//前ゼロパディング
iLb = wStr;
}else{


}
String strL = new String(iLb);
String strR = new String(iRb);

return strL.compareTo( strR );
}
}

Arrays.sort(files,new FileSort());

for (int i = 0; i < files.length; i++) {

File file = files[i];
System.out.println(file.getName());

}

}

}