You could try using the FileUtils library.
https://commons.apache.org/proper/commons-io/javadocs/api-2.5/org/apache/commons/io/FileUtils.html
You can specify extensions of your files, of which your directories should not be returned.
var srcDirectory = new java.io.File("C:\\myDirectory\\path\\");
// Use this to filter by extensions
//var extensions = StringUtils.splitByWholeSeparator('pdf,json', ',');
//Use null to list all files regardless of extension
var extensions = null;
var FileUtils = org.apache.commons.io.FileUtils;
var listFiles = FileUtils.convertFileCollectionToFileArray(FileUtils.listFiles(srcDirectory, extensions, false));
for (var i = 0; i < listFiles.length; i++) {
qie.debug(listFiles[i].getName());
}