help make this, the following code finds the txt files in the folder, and how to make it lists the names of files without extensions. Here\'s the code:
Strin
If I understand correctly, you want to list all files in a folder, regardless of their extension. In this case, use:
String list[] = new File("C:\\Users\\Eric\\Desktop\\txt\\").list(new FileFilter() {
public boolean accept(File file) {
return file.isFile();
}
});
Edit: Ok, I did not understand you correctly. You want to strip the extension from the file name in your if statement. You can use substring
combined with lastIndexOf
:
String name = list[i];
String nameWithoutExtension = name.substring(0, name.lastIndexOf("."));
or, since all your extensions are ".txt", the following will work too:
String nameWithoutExtension = name.substring(0, name.lastIndexOf(".txt"));