try {
List<String> contents = new ArrayList<String>();
File dirFile = new File(dirPath);
if (!dirFile.exists() || !dirFile.isDirectory()) {
throw new CedarRuntimeException("Directory does not exist.");
}
File[] files = dirFile.listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
contents.add(file.getName());
if (file.isDirectory()) {
if (recursive) {
List<String> subdir = getDirContents(file.getCanonicalPath(), recursive);
for (String entry : subdir) {
String path = join(file.getName(), entry);
contents.add(path);
}
}
}
}
return contents;
} catch (Exception e) {
throw new CedarRuntimeException("Error getting dir contents: " + e.getMessage(), e);
}
}