Example usage for java.io File listFiles

List of usage examples for java.io File listFiles

Introduction

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

Prototype

public File[] listFiles(FileFilter filter) 

Source Link

Document

Returns an array of abstract pathnames denoting 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

/**
 * Gets a list of all hidden files in the given directory.
 *
 * @param dirName the directory//from ww w . j a va2  s .  c om
 * @return list of hidden files
 */
public static File[] getHiddenFilesInDir(final String dirName) {
    final File dir = new File(dirName);
    return dir.listFiles(HIDDEN_FILES_FILTER);
}

From source file:edu.rice.cs.bioinfo.programs.phylonet.PhyloNetAAT.java

public static TestSuite suite() throws Throwable {
    TestSuite aatSuite = new TestSuite();

    File currentDir = new File(".");

    for (final File file : currentDir.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".txt");
        }/*from  w w w  . ja va2s . co m*/
    })) {

        new AATTestCase(file).runTest();

    }

    return aatSuite;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.EvalHelper.java

public static File[] listSubFolders(File folder) {
    File[] subFolders = folder.listFiles(new FileFilter() {
        @Override/*  w  ww .  j  ava2 s.c o m*/
        public boolean accept(File pathname) {
            return pathname.isDirectory();
        }
    });

    if (subFolders.length == 0) {
        throw new IllegalStateException("No sub-folders found in " + folder.getAbsolutePath());
    }

    return subFolders;
}

From source file:Main.java

public final static int getNumCores() {
    // Private Class to display only CPU devices in the directory listing
    class CpuFilter implements FileFilter {
        @Override/* www . j av  a 2s  .  com*/
        public boolean accept(File pathname) {
            // Check if filename is "cpu", followed by a single digit number
            if (Pattern.matches("cpu[0-9]", pathname.getName())) {
                return true;
            }
            return false;
        }
    }
    try {
        // Get directory containing CPU info
        File dir = new File("/sys/devices/system/cpu/");
        // Filter to only list the devices we care about
        File[] files = dir.listFiles(new CpuFilter());
        // Return the number of cores (virtual CPU devices)
        return files.length;
    } catch (Exception e) {
        return Runtime.getRuntime().availableProcessors();
    }
}

From source file:hu.bme.mit.incqueryd.engine.test.util.TestCaseFinder.java

public static File[] getTestCases(final String wildcard) {
    final File dir = new File(TestConstants.TEST_CASES_DIRECTORY);
    final FileFilter fileFilter = new WildcardFileFilter(wildcard);
    final File[] files = dir.listFiles(fileFilter);
    return files;
}

From source file:Main.java

public static int getNumCores() {// Private Class to display only CPU
    // devices in the directory listing
    class CpuFilter implements FileFilter {
        @Override/*from  w w w.  jav  a2s .c  om*/
        public boolean accept(File pathname) {
            // Check if filename is "cpu", followed by a single digit number
            if (Pattern.matches("cpu[0-9]", pathname.getName())) {
                return true;
            }
            return false;
        }
    }

    try {
        // Get directory containing CPU info
        File dir = new File("/sys/devices/system/cpu/");
        // Filter to only list the devices we care about
        File[] files = dir.listFiles(new CpuFilter());
        // Return the number of cores (virtual CPU devices)
        return files.length;
    } catch (Exception e) {
        e.printStackTrace();
        // Default to return 1 core
        return 1;
    }
}

From source file:funnycats.Utils.java

public static List<FunnyCat> getFunnyCats(final File directory) {
    final List funnyCats = new ArrayList();

    File[] pictures = directory.listFiles(pictureFileNameFilter);

    long index = 1;
    for (File picture : pictures) {
        FunnyCat funnyCat = new FunnyCat();
        funnyCat.setId(index);//from   ww w  . j  ava2  s  .co  m
        funnyCat.setFileName(picture.getName());
        funnyCat.setVotes(0);
        index += 1;

        funnyCats.add(funnyCat);
    }

    return funnyCats;
}

From source file:Main.java

/** 
 * Gets the number of cores available in this device, across all processors. 
 * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu" 
 * @return The number of cores, or 1 if failed to get result 
 *///  w  w w  .j  a  va  2 s .  co m
public static int getNumCores() {
    try {
        //Get directory containing CPU info 
        File dir = new File("/sys/devices/system/cpu/");
        //Filter to only list the devices we care about 
        File[] files = dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                //Check if filename is "cpu", followed by a single digit number 
                if (Pattern.matches("cpu[0-9]", pathname.getName())) {
                    return true;
                }
                return false;
            }

        });
        //Return the number of cores (virtual CPU devices) 
        return files.length;
    } catch (Exception e) {
        //Default to return 1 core 
        return 1;
    }
}

From source file:Main.java

public static File findParentDirContainerFile(File file, final String fileKey) {
    if (fileKey.equals(file.getName())) {
        return file;
    }//  ww w  . j  a  v a  2  s . co  m
    File[] guessFileKeys = file.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return fileKey.equals(name);
        }
    });
    if (guessFileKeys.length > 0) {
        return file;
    }
    if (file.getParentFile() != null) {
        return findParentDir(file.getParentFile(), fileKey);
    } else {
        return file.getParentFile();
    }
}

From source file:Main.java

/**
 * Gets the number of cores available in this device, across all processors.
 * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu"
 *
 * @return The number of cores, or 1 if failed to get result
 *//*  w ww  .  ja v a 2 s .c  o m*/
public static int getNumCores() {
    //Private Class to display only CPU devices in the directory listing
    class CpuFilter implements FileFilter {
        @Override
        public boolean accept(File pathname) {
            //Check if filename is "cpu", followed by a single digit number
            if (Pattern.matches("cpu[0-9]+", pathname.getName())) {
                return true;
            }
            return false;
        }
    }

    try {
        //Get directory containing CPU info
        File dir = new File("/sys/devices/system/cpu/");
        //Filter to only list the devices we care about
        File[] files = dir.listFiles(new CpuFilter());
        //Return the number of cores (virtual CPU devices)
        return files.length;
    } catch (Exception e) {
        //Default to return 1 core
        return 1;
    }
}