throws NodeOSException
{
Path sp = translatePath(dn);
Context cx = Context.enter();
if (!Files.isDirectory(sp)) {
throw new NodeOSException(Constants.ENOTDIR, sp.toString());
}
try {
final ArrayList<String> paths = new ArrayList<String>();
Set<FileVisitOption> options = Collections.emptySet();
Files.walkFileTree(sp, options, 1,
new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path child, BasicFileAttributes attrs)
{
if (log.isTraceEnabled()) {
log.trace(" " + child.getFileName());
}
paths.add(child.getFileName().toString());
return FileVisitResult.CONTINUE;
}
});
Object[] objs = new Object[paths.size()];
paths.toArray(objs);
Scriptable fileList = cx.newArray(this, objs);
if (log.isDebugEnabled()) {
log.debug("readdir({}) = {}", dn, objs.length);
}
return new Object[] { Context.getUndefinedValue(), fileList };
} catch (IOException ioe) {
throw new NodeOSException(getErrorCode(ioe), ioe, dn);
} finally {
Context.exit();
}
}