List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:Main.java
public static void main(String[] args) { File f = new File("c:/test"); FileFilter filter = new FileFilter() { @Override//from w w w .j av a 2 s . co m public boolean accept(File pathname) { return pathname.isFile(); } }; // returns pathnames for files and directory File[] paths = f.listFiles(filter); for (File path : paths) { System.out.println(path); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { File dir = new File("c:\\temp"); FileFilter fileFilter = new FileFilter() { public boolean accept(File file) { return file.isDirectory(); }// www .j a v a 2 s .co m }; File[] files = dir.listFiles(fileFilter); }
From source file:com.siva.filewritterprogram.Mp3FileWritterTool.java
public static void main(String[] args) { File directory = new File("D:\\Siva\\Entertainment\\EvergreenHits"); FileFilter filter = new FileFilter() { @Override/*from ww w.jav a 2s. c om*/ public boolean accept(File file) { if (file.getName().endsWith(".mp3")) { return true; } else { return false; } } }; File[] subdirs = directory.listFiles(); for (File subDir : subdirs) { try { System.out.println("Going to read files under : " + subDir); if (subDir.isDirectory()) { File[] files = subDir.listFiles(filter); if (files != null) { for (File file : files) { FileUtils.copyFileToDirectory(file, new File(directory.getPath() + "\\toTransfer")); } } else { System.out.println("There are no songs inside. [" + subDir.getName() + "]"); } } else { System.out.println("Not a directory. [" + subDir.getName() + "]"); } } catch (IOException ex) { Logger.getLogger(Mp3FileWritterTool.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.ms.commons.test.tool.GenerateTestCase.java
public static void main(String[] args) { if (args.length < 2) { System.err.println("Usage:\r\n.frameworktest_maketests antx|maven fileter"); System.exit(-1);//from ww w .j a v a 2 s. c om } final com.ms.commons.test.runner.filter.expression.internal.Expression filterExpression; try { System.out.println("Filter: " + args[1]); filterExpression = ExpressionParseUtil.parse(args[1], new SimpleExpressionBuiler() { public AbstractSimpleExpression build(String value) { return new StringExpressionImpl(value); } }); } catch (ParseException e) { throw ExceptionUtil.wrapToRuntimeException(e); } final FullClassNameFilter fullClassNameFilter = new FullClassNameFilter() { public boolean accept(String fullClassName) { return ((Boolean) filterExpression.evaluate(fullClassName)).booleanValue(); } }; String userDir = System.getProperty("user.dir"); ProjectPath pp = getProjectPath(args[0]); final String mainSource = userDir + File.separator + pp.getMainSource(); final String testSource = userDir + File.separator + pp.getTestSource(); FileUtil.listFiles(null, new File(mainSource), new FileFilter() { public boolean accept(File pathname) { if (pathname.isDirectory()) { return !pathname.toString().contains(".svn"); } if (pathname.toString().contains(".svn")) { return false; } if (!pathname.toString().toLowerCase().endsWith(".java")) { return false; } try { processJavaFile(pathname, testSource, fullClassNameFilter); } catch (Exception e) { System.err.println("Parse java file failed:" + pathname); e.printStackTrace(); } return false; } }); }
From source file:Main.java
static public File[] getDirectories(File file) { return file.listFiles(new FileFilter() { @Override/*w ww. j a v a 2 s. co m*/ public boolean accept(File pathname) { return pathname.isDirectory(); } }); }
From source file:Main.java
private static File[] listFiles(File dir) { File[] fileList = dir.listFiles(new FileFilter() { public boolean accept(File file) { return file.isFile(); }/*from w w w. j a v a 2 s .co m*/ }); return fileList; }
From source file:Main.java
public static int getNumCores() { try {//from ww w. ja va 2 s .c om File dir = new File("/sys/devices/system/cpu/"); File[] files = dir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return Pattern.matches("cpu[0-9]", pathname.getName()); } }); return files.length; } catch (Exception e) { e.printStackTrace(); return 1; } }
From source file:Main.java
public static int cpuNums() { int nums = 1; try {//from w w w . java 2 s . co m File file = new File("/sys/devices/system/cpu/"); File[] files = file.listFiles(new FileFilter() { @Override public boolean accept(File arg0) { if (Pattern.matches("cpu[0-9]", arg0.getName())) { return true; } return false; } }); nums = files.length; } catch (Exception e) { e.printStackTrace(); } return nums; }
From source file:Main.java
public static Enumeration getAllFilesIn(File dir) { File[] files;// w w w .ja v a2s . co m if (dir.isDirectory()) { files = dir.listFiles(new FileFilter() { public boolean accept(File f) { if (f.isDirectory()) return false; return (f.getName().endsWith(".txt")); } }); Arrays.sort(files); } else { files = new File[] { dir }; } Vector vect = new Vector(files.length); for (int i = 0; i < files.length; ++i) vect.addElement(files[i]); return vect.elements(); }
From source file:Main.java
public static Collection<File> listFiles(File directory, String suffix) { final String _suffix = "." + suffix; FileFilter filter = new FileFilter() { @Override/*from ww w. ja v a2 s . c o m*/ public boolean accept(File file) { if (file.isDirectory()) return true; String name = file.getName(); int endLen = _suffix.length(); if (name.regionMatches(true, name.length() - endLen, _suffix, 0, endLen)) { return true; } return false; } }; if (!directory.isDirectory()) { throw new IllegalArgumentException("Parameter 'directory' is not a directory"); } if (filter == null) { throw new NullPointerException("Parameter 'fileFilter' is null"); } Collection<File> files = new LinkedList<File>(); innerListFiles(files, directory, filter); return files; }