public static void main(String[] args) { File path = new File("."); String[] list; if (args.length == 0) list = path.list(); else list = path.list(new DirFilter(args[0])); Arrays.sort(list, String.CASE_INSENSITIVE_ORDER); for (String dirItem : list) System.out.println(dirItem); }
/** * Get the contents of a file. * * @param in * @return * @throws IOException */ public String _cat(String args[]) throws IOException { verifyCommand(args, "${cat;<in>}, get the content of a file", null, 2, 2); File f = domain.getFile(args[1]); if (f.isFile()) { return IO.collect(f); } else if (f.isDirectory()) { return Arrays.toString(f.list()); } else { try { URL url = new URL(args[1]); return IO.collect(url, "UTF-8"); } catch (MalformedURLException mfue) { // Ignore here } return null; } }
/** * Locate root path. * * @param root The user-specified root path. */ private void locateRoot(String root) { // Locate default root folder. if (root == null) { File pwd = new File(".").getAbsoluteFile(); File f = pwd; String[] l = null; // Detect intl-style/xxx/htdocs by finding "js" and "css" in sub folders. do { f = f.getParentFile(); if (f == null) { break; } l = f.list( new FilenameFilter() { private Pattern pattern = Pattern.compile("^(?:js|css)$"); public boolean accept(File dir, String name) { return pattern.matcher(name).matches(); } }); } while (l.length != 2); // If present, use intl-style/xxx/htdocs as root folder for Alibaba. if (f != null) { this.root = canonize(f); // Else use present working folder as root folder. } else { this.root = canonize(pwd); } // Use user-specified root folder. } else { File f = new File(root); if (f.exists()) { this.root = canonize(f); } else { App.exit("The user-specified root folder " + root + " does not exist."); } } }
private void listFiles(String basePath, String path, String extension, Vector<String> vector) { File folder = new File(path); String[] list = folder.list(); if (list != null) { for (String item : list) { if (item.charAt(0) == '.') continue; File file = new File(path, item); String newPath = file.getAbsolutePath(); if (newPath.startsWith(basePath)) { newPath = newPath.substring(basePath.length()); } if (extension == null || item.toLowerCase().endsWith(extension)) { vector.add(newPath); } if (file.isDirectory()) { listFiles(basePath, file.getAbsolutePath(), extension, vector); } } } }
public void _workspace(WorkspaceOptions opts) throws Exception { File base = bnd.getBase(); String name = opts._arguments().get(0); File workspaceDir = Processor.getFile(base, name); name = workspaceDir.getName(); base = workspaceDir.getParentFile(); if (base == null) { bnd.error( "You cannot create a workspace in the root (%s). The parent of a workspace %n" + "must be a valid directory. Recommended is to dedicate a directory to %n" + "all (or related) workspaces.", workspaceDir); return; } if (!opts.anyname() && !Verifier.isBsn(name)) { bnd.error( "You specified a workspace name that does not follow the recommended pattern " + "(it should be like a Bundle Symbolic name). It is a bit pedantic but it " + "really helps hwne you get many workspaces. If you insist on this name, use the -a/--anyname option."); return; } Workspace ws = bnd.getWorkspace((File) null); if (ws != null && ws.isValid()) { bnd.error( "You are currently in a workspace already (%s) in %s. You can only create a new workspace outside an existing workspace", ws, base); return; } File eclipseDir = workspaceDir; workspaceDir.mkdirs(); if (!opts.single()) workspaceDir = new File(workspaceDir, "scm"); workspaceDir.mkdirs(); if (!base.isDirectory()) { bnd.error("Could not create directory for the bnd workspace %s", base); } else if (!eclipseDir.isDirectory()) { bnd.error("Could not create directory for the Eclipse workspace %s", eclipseDir); } if (!workspaceDir.isDirectory()) { bnd.error("Could not create the workspace directory %s", workspaceDir); return; } if (!opts.update() && !opts.force() && workspaceDir.list().length > 0) { bnd.error( "The workspace directory %s is not empty, specify -u/--update to update or -f/--force to replace", workspaceDir); } InputStream in = getClass().getResourceAsStream("/templates/enroute.zip"); if (in == null) { bnd.error("Cannot find template in this jar %s", "/templates/enroute.zip"); return; } Pattern glob = Pattern.compile("[^/]+|cnf/.*|\\...+/.*"); copy(workspaceDir, in, glob, opts.force()); File readme = new File(workspaceDir, "README.md"); if (readme.isFile()) IO.copy(readme, bnd.out); bnd.out.printf( "%nWorkspace %s created.%n%n" // + " Start Eclipse:%n" // + " 1) Select the Eclipse workspace %s%n" // + " 2) Package Explorer context menu: Import/General/Existing Projects from %s%n" + "%n" + "", // workspaceDir.getName(), eclipseDir, workspaceDir); }
public SortedDirList2(File dir) { dirList = dir.list(); Arrays.sort(dirList, String.CASE_INSENSITIVE_ORDER); }