superclass-app/src/main/java/net/altimate/app/ListFilesInDir.java

58 lines
1.3 KiB
Java
Raw Normal View History

2025-01-05 15:12:26 +01:00
package net.altimate.app;
import java.io.File;
2025-01-05 19:12:22 +01:00
import static java.util.regex.Pattern.matches;
2025-01-05 15:12:26 +01:00
public class ListFilesInDir {
2025-01-05 19:12:22 +01:00
public static String[] listFilesInDir(String directory) {
2025-01-05 15:12:26 +01:00
File filesInDir = null;
File[] paths;
2025-01-05 19:12:22 +01:00
String match = "^.*.smart$";
int count=0;
int filterArrayLength=0;
2025-01-05 15:12:26 +01:00
try {
filesInDir = new File(directory);
2025-01-05 19:12:22 +01:00
//paths = filesInDir.listFiles();
//for(File path:paths) {
// System.out.println(path.getName().matches(".smart"));
// System.out.println("ok");
//
2025-01-05 15:12:26 +01:00
2025-01-05 19:12:22 +01:00
} catch(Exception efile){
2025-01-05 15:12:26 +01:00
2025-01-05 19:12:22 +01:00
efile.printStackTrace();
2025-01-05 15:12:26 +01:00
}
2025-01-05 19:12:22 +01:00
paths = filesInDir.listFiles();
for (File path:paths) {
if (path.getName().matches(match)) {
filterArrayLength++;
}
}
2025-01-05 15:12:26 +01:00
2025-01-05 19:12:22 +01:00
String[] filter = new String[filterArrayLength];
for (File path:paths) {
if (path.getName().matches(match)) {
filter[count] = path.getName();
count++;
}
}
2025-01-05 15:12:26 +01:00
2025-01-05 19:12:22 +01:00
//return filesInDir.list();
System.out.println("ListFilesInDir wurde aufgerufen");
return filter;
2025-01-05 15:12:26 +01:00
}
}
2025-01-05 19:12:22 +01:00