Java File Name Get getFileNames(File path, Vector result)

Here you can find the source of getFileNames(File path, Vector result)

Description

get File Names

License

Open Source License

Declaration

public static void getFileNames(File path, Vector<String> result) throws Exception 

Method Source Code

//package com.java2s;
/*//from  w  w  w . j a  va  2s  . co  m
 * Biocep: R-based Platform for Computational e-Science.
 *  
 * Copyright (C) 2007-2009 Karim Chine - karim.chine@m4x.org
 *  
 * Copyright (C) 2007 EMBL-EBI-Microarray Informatics
 *  
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.BufferedReader;

import java.io.File;
import java.io.FileFilter;

import java.io.FileReader;

import java.util.Vector;

public class Main {
    public static void getFileNames(File path, Vector<String> result) throws Exception {
        File[] files = path.listFiles(new FileFilter() {
            public boolean accept(File pathname) {
                return pathname.isDirectory() || pathname.toString().toLowerCase().endsWith(".java")
                        || pathname.toString().toLowerCase().endsWith(".r")
                        || pathname.toString().toLowerCase().endsWith("build.xml");
            }
        });
        if (files == null)
            return;
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                getFileNames(files[i], result);
            } else {
                String name = files[i].getAbsolutePath();
                System.out.println(name + " --> " + countLines(name));
                result.add(name);
            }
        }
    }

    public static int countLines(String fileName) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader(fileName));
        int counter = 0;
        while ((br.readLine()) != null)
            ++counter;
        return counter;
    }
}

Related

  1. getFileNameOnly(String fileName)
  2. getFileNameOnlyFromFileObject(File fileToProcess)
  3. getFileNamePart(final File file)
  4. getFilenameParts(File file)
  5. getFileNames(byte[] zipFile)
  6. getFileNames(File zipFile, Pattern pattern)
  7. getFileNames(File[] files)
  8. getFilenames(File[] files)
  9. getFileNames(final String path, final String regex)