private void executeAllScriptsInDirectory( File dir, boolean recurseDown, int maxDepth, int currentDepth) { if (dir.isDirectory()) { for (File file : dir.listFiles()) { if (file.isDirectory() && recurseDown && maxDepth > currentDepth) { if (Config.SCRIPT_DEBUG) { _log.info("Entering folder: " + file.getName()); } this.executeAllScriptsInDirectory(file, recurseDown, maxDepth, currentDepth + 1); } else if (file.isFile()) { try { String name = file.getName(); int lastIndex = name.lastIndexOf('.'); String extension; if (lastIndex != -1) { extension = name.substring(lastIndex + 1); ScriptEngine engine = getEngineByExtension(extension); if (engine != null) { this.executeScript(engine, file); } } } catch (FileNotFoundException e) { // should never happen e.printStackTrace(); } catch (ScriptException e) { reportScriptFileError(file, e); // e.printStackTrace(); } } } } else throw new IllegalArgumentException( "The argument directory either doesnt exists or is not an directory."); }
public static String[] get_filelist(String path, boolean nodirs, boolean nofiles) { File folder = new File(path); if (folder.isDirectory()) { File[] listOfFiles = folder.listFiles(); java.util.Vector<String> r = new java.util.Vector<String>(); for (int i = 0; listOfFiles != null && i < listOfFiles.length; i++) { if ((listOfFiles[i].isFile() && !nofiles) || (listOfFiles[i].isDirectory() && !nodirs)) { r.add(listOfFiles[i].getName()); } } return r.toArray(new String[0]); } else { return null; // A: no existe o no es directorio } }