Example usage for java.io File list

List of usage examples for java.io File list

Introduction

In this page you can find the example usage for java.io File list.

Prototype

public String[] list(FilenameFilter filter) 

Source Link

Document

Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.

Usage

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.DirectoryListerImpl.java

/**
 * A method to get all files by a wildcard pattern 
 * @param dirName name of the directory to look
 * @param filePatternList a list of patterns
 * @return an arrays of files that match the patterns
 * @throws IOException /*  www. j  ava  2  s .  c  o  m*/
 */
public static File[] getFilesByPattern(final String dirName, final List<String> filePatternList) {

    File[] listOfFiles = null;

    if (StringUtils.isNotEmpty(dirName) && filePatternList != null && filePatternList.size() > 0) {

        final File dir = new File(dirName);
        String[] dataSetFiles = dir.list(new WildcardFileFilter(filePatternList));
        if (dataSetFiles != null && dataSetFiles.length > 0) {
            listOfFiles = new File[dataSetFiles.length];
            for (int i = 0; i < dataSetFiles.length; i++) {
                try {
                    listOfFiles[i] = new File(dir.getCanonicalPath() + File.separator + dataSetFiles[i]);
                } catch (IOException e) {
                    // should never get here, but just in case we do , just return with null
                    // meaning that no files by pattern could be found
                    return null;
                }
            }
        }

    }
    return listOfFiles;
}

From source file:Main.java

/**
 * Obtains a list of files that live in the specified directory and match the glob pattern.
 *//*  ww w.  j av a  2  s  .c om*/
public static String[] getFiles(File dir, String glob) {
    String regex = globToRegex(glob);
    final Pattern pattern = Pattern.compile(regex);
    String[] result = dir.list(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            Matcher matcher = pattern.matcher(name);
            return matcher.matches();
        }
    });
    Arrays.sort(result);

    return result;
}

From source file:edu.cmu.cs.lti.ark.fn.identification.latentmodel.LatentAlphabetCreationThreaded.java

/**
 * Combines the multiple alphabet files created by createLocalAlphabets into one
 * alphabet file/*  w  w  w . j  a v  a2 s  .  com*/
 */
public static void combineAlphabets(File alphabetDir) throws IOException {
    final String[] files = alphabetDir.list(LOCAL_ALPHABET_FILENAME_FILTER);
    final Set<String> alphabet = Sets.newHashSet();
    for (String file : files) {
        final String path = alphabetDir.getAbsolutePath() + "/" + file;
        if (logger.isLoggable(Level.INFO))
            logger.info("reading path: " + path);
        final Map<String, Integer> localAlphabet = readAlphabetFile(path);
        alphabet.addAll(localAlphabet.keySet());
    }
    writeAlphabetFile(alphabet, alphabetDir.getAbsolutePath() + "/" + ALPHABET_FILENAME);
}

From source file:FileUtil.java

public static String[] getFileNames(String dirPath, FilenameFilter fileNameFilter) throws Exception {
    String fileNames[] = null;//  w  w  w  .  j a va 2s.c  om
    File dir = new File(dirPath);
    if (dir.isDirectory()) {
        if (fileNameFilter != null) {
            fileNames = dir.list(fileNameFilter);
        } else {
            fileNames = dir.list();
        }
    }
    return fileNames;
}

From source file:eu.annocultor.utils.OntologySubtractor.java

private static Collection<String> listNameStamsForFilesWithDeletedStatements(File sourceDir) {
    Set<String> stamms = new HashSet<String>();
    for (String file : sourceDir.list(new FilenameFilter() {

        @Override/*  w w w . jav a2 s  .co m*/
        public boolean accept(File dir, String name) {
            return name.endsWith(DELETED_RDF);
        }
    })) {
        String stam = StringUtils.substringBeforeLast(file, DELETED_RDF);
        // allow one word before: real.name.*.deleted.rdf
        stam = StringUtils.substringBeforeLast(stam, ".");
        stamms.add(stam);
    }
    return stamms;
}

From source file:edu.cmu.cs.lti.ark.fn.identification.latentmodel.TrainBatchModelDerThreaded.java

/** Gets the list of all feature files */
private static List<String> getEventFiles(File eventsDir) {
    final String[] files = eventsDir.list(featureFilenameFilter);
    Arrays.sort(files, featureFilenameComparator);
    final List<String> eventFiles = Lists.newArrayListWithExpectedSize(files.length);
    for (String file : files)
        eventFiles.add(eventsDir.getAbsolutePath() + "/" + file);
    logger.info("Total number of datapoints:" + eventFiles.size());
    return eventFiles;
}

From source file:ca.uqac.dim.net.verify.NetworkChecker.java

private static Network loadNetworkFromDirectory(String dirname, String blob, String slash) throws IOException {
    Network net = new Network();
    File dir = new File(dirname);
    String[] children = dir.list(new NetworkChecker.BlobFilter(blob));
    for (String filename : children) {
        String s = Utilities.readFileAsString(dirname + slash + filename);
        NetworkNode nn = new NetworkNode(s);
        net.add(nn);/* w  w  w.j  ava 2 s  .co  m*/
    }
    return net;
}

From source file:edu.uci.ics.asterix.installer.test.AsterixClusterLifeCycleIT.java

@BeforeClass
public static void setUp() throws Exception {
    //testcase setup
    TestCaseContext.Builder b = new TestCaseContext.Builder();
    testCaseCollection = b.build(new File(PATH_BASE));
    File outdir = new File(PATH_ACTUAL);
    outdir.mkdirs();/*from   w w w  .  j  av a 2  s. com*/

    //vagrant setup
    File installerTargetDir = new File(asterixProjectDir, "target");
    System.out.println(managixFolderName);
    managixFolderName = installerTargetDir.list(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return new File(dir, name).isDirectory() && name.startsWith("asterix-installer")
                    && name.endsWith("binary-assembly");
        }

    })[0];
    invoke("cp", "-r", installerTargetDir.toString() + "/" + managixFolderName,
            asterixProjectDir + "/" + CLUSTER_BASE);

    logOutput(remoteInvoke("cp -r /vagrant/" + managixFolderName + " /tmp/asterix").getInputStream());

    logOutput(managixInvoke("configure").getInputStream());
    logOutput(managixInvoke("validate").getInputStream());

    Process p = managixInvoke("create -n vagrant-ssh -c /vagrant/cluster.xml");
    String pout = processOut(p);
    LOGGER.info(pout);
    Assert.assertTrue(checkOutput(pout, "ACTIVE"));
    //TODO: I should check for 'WARNING' here, but issue 764 stops this from being reliable 
    LOGGER.info("Test start active cluster instance PASSED");

    Process stop = managixInvoke("stop -n vagrant-ssh");
    Assert.assertTrue(checkOutput(stop.getInputStream(), "Stopped Asterix instance"));
    LOGGER.info("Test stop active cluster instance PASSED");
}

From source file:at.riemers.velocity2js.velocity.Velocity2Js.java

public static List<I18NBundle> getBundles(String resource) {
    List<I18NBundle> bundles = new ArrayList<I18NBundle>();
    if (resource != null) {
        try {/*from  w  w  w  . j av  a2 s  .c  o m*/
            File rb = new File(resource);
            String rbDirName = rb.getParent();
            String resourceName = rb.getName();
            //log("[velocity2js] - " + resourceName);
            if (rbDirName == null) {
                rbDirName = ".";
            }
            File rbDir = new File(rbDirName);
            String[] files = rbDir.list(new PropertiesFilter(resourceName));
            for (String file : files) {
                bundles.add(new I18NBundle(rbDirName, file));
            }
        } catch (Exception ex) {
            log.error("[velocity2js] - " + ex.toString(), ex);
        }
    } else {
        bundles.add(new I18NBundle());
    }
    return bundles;
}

From source file:AIR.Common.Web.Session.CaseInsensitiveFileNameFilter.java

public static String getFile(String directory, final String filePathSegment) {
    File f = new File(directory);
    if (f.isDirectory()) {
        String[] filesInFolder = f.list(new FilenameFilter() {
            @Override/*from   www .j  a v  a  2 s  .  c om*/
            public boolean accept(File dir, String name) {
                if (StringUtils.equalsIgnoreCase(name, filePathSegment))
                    return true;
                return false;
            }
        });
        // We are only expecting one match as we are doing a case insensitive
        // match.
        if (filesInFolder != null && filesInFolder.length > 0)
            return filesInFolder[0];
    }
    return filePathSegment;
}