mirror of
https://github.com/processing/processing4.git
synced 2026-02-03 05:39:18 +01:00
fix for bug 65.. recursive 'data' folder
This commit is contained in:
@@ -880,6 +880,46 @@ public class Base {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a list of all files within the specified folder,
|
||||
* and returns a list of their relative paths.
|
||||
* Ignores any files/folders prefixed with a dot.
|
||||
*/
|
||||
static public String[] listFiles(String path, boolean relative) {
|
||||
return listFiles(new File(path), relative);
|
||||
}
|
||||
|
||||
static public String[] listFiles(File folder, boolean relative) {
|
||||
String path = folder.getAbsolutePath();
|
||||
Vector vector = new Vector();
|
||||
listFiles(relative ? (path + File.separator) : "", path, vector);
|
||||
String outgoing[] = new String[vector.size()];
|
||||
vector.copyInto(outgoing);
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
static protected void listFiles(String basePath,
|
||||
String path, Vector vector) {
|
||||
File folder = new File(path);
|
||||
String list[] = folder.list();
|
||||
if (list == null) return;
|
||||
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i].charAt(0) == '.') continue;
|
||||
|
||||
File file = new File(path, list[i]);
|
||||
String newPath = file.getAbsolutePath();
|
||||
if (newPath.startsWith(basePath)) {
|
||||
newPath = newPath.substring(basePath.length());
|
||||
}
|
||||
vector.add(newPath);
|
||||
if (file.isDirectory()) {
|
||||
listFiles(basePath, newPath, vector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Equivalent to the one in PApplet, but static (die() is removed)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user