Example usage for org.apache.commons.io FileUtils listFiles

List of usage examples for org.apache.commons.io FileUtils listFiles

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils listFiles.

Prototype

public static Collection listFiles(File directory, String[] extensions, boolean recursive) 

Source Link

Document

Finds files within a given directory (and optionally its subdirectories) which match an array of extensions.

Usage

From source file:edu.ehu.galan.lite.model.Corpus.java

/**
 * Loads a corpus from a given folder and scans recursively all the documents inside it,
 * then it reorder using the file name (uses FilesUtils from CommonsIO), you need to choose
 * the source of knowledge to be used (Wikipedia or Wordnet)
 * @param pRootFolder//  w  ww .  ja v a2s .  com
 * @param pType 
 */

public void loadCorpus(String pRootFolder, Document.SourceType pType) {
    File file = new File(pRootFolder);
    rootFolder = pRootFolder;
    Collection<File> documents = FileUtils.listFiles(file, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    documents.stream().sorted((d1, d2) -> d1.getName().compareTo(d2.getName()))
            .forEachOrdered((f) -> docList.add(new Document(f.getAbsolutePath(), f.getName())));
}

From source file:com.denimgroup.threadfix.framework.impl.struts.StrutsEndpointMappings.java

public StrutsEndpointMappings(@Nonnull File rootDirectory) {
    this.rootDirectory = rootDirectory;
    //        urlToControllerMethodsMap = map();
    File strutsConfigFile = null;
    File strutsPropertiesFile = null;

    entityMappings = new EntityMappings(rootDirectory);

    if (rootDirectory.exists()) {
        javaFiles = FileUtils.listFiles(rootDirectory, new FileExtensionFileFilter("java"),
                TrueFileFilter.TRUE);//from w  ww  . ja v  a 2s. c om
    } else {
        javaFiles = Collections.emptyList();
    }

    String[] configExtensions = { "xml", "properties" };
    Collection configFiles = FileUtils.listFiles(rootDirectory, configExtensions, true);

    for (Iterator iterator = configFiles.iterator(); iterator.hasNext();) {
        File file = (File) iterator.next();
        if (file.getName().equals(STRUTS_CONFIG_NAME))
            strutsConfigFile = file;
        if (file.getName().equals(STRUTS_PROPERTIES_NAME))
            strutsPropertiesFile = file;
        if (strutsConfigFile != null && strutsPropertiesFile != null)
            break;
    }

    strutsActionExtension = StrutsPropertiesParser.getStrutsProperties(strutsPropertiesFile)
            .getProperty("struts.action.extension", "action");
    if (strutsActionExtension == null)
        strutsActionExtension = "";
    strutsActionExtension = strutsActionExtension.trim();
    if (strutsActionExtension.length() > 0 && !strutsActionExtension.startsWith(".")) {
        strutsActionExtension = "." + strutsActionExtension;
    }

    strutsPackages = StrutsXmlParser.parse(strutsConfigFile);

    generateMaps();

}

From source file:RemoveDuplicateFiles.java

public static void addActionHandlers(Stage primaryStage) {
    //Sort Files Button Pressed.
    sortFilesButton.setOnAction((ActionEvent event) -> {
        //Move to the SortFiles window
        new FileSort(primaryStage);
    });/*w w w .j ava 2s.  com*/

    //Batch Rename Button Pressed
    batchRenameButton.setOnAction((ActionEvent event) -> {
        //Move to the BatchRename window
        new BatchRename(primaryStage);
    });

    //Action Handler: remove the duplicate files in the directory.
    rmvButton.setOnAction((ActionEvent event) -> {
        //Clear the actionTarget
        actionTarget.setFill(Color.BLACK);
        actionTarget.setText("");

        //Make sure we have the right path
        selectedDirectory = new File(address.getText());

        if (selectedDirectory != null && selectedDirectory.isDirectory()) {
            //Grab the list of file types from the textbox
            String[] extensions = UtilFunctions.parseFileTypes(fileTypes.getText());

            //Grab the list of files in the selectedDirectory
            List<File> files = (List<File>) FileUtils.listFiles(selectedDirectory, extensions, true);
            HashSet<String> hashCodes = new HashSet<>();
            ArrayList<File> duplicates = new ArrayList<>();

            //Progress reporting values
            actionTarget.setFill(Color.BLACK);
            int totalFileCount = files.size();
            int filesProcessed = 0;

            //Find the duplicate files
            for (File f : files) {
                try {
                    //Update the status
                    filesProcessed++;
                    actionTarget.setText("Processing file " + filesProcessed + " of " + totalFileCount);

                    //Grab the file's hash code
                    String hash = UtilFunctions.makeHash(f);

                    //If we already have a file matching that hash code
                    if (hashCodes.contains(hash)) {
                        //Add the file to the list of files to be deleted
                        duplicates.add(f);
                    } else {
                        hashCodes.add(hash);
                    }

                } catch (Exception except) {
                }
            } //End for

            //Progress reporting
            filesProcessed = 0;
            totalFileCount = duplicates.size();
            Iterator<File> itr = duplicates.iterator();

            //Remove the duplicate files
            while (itr.hasNext()) {
                try {
                    //Update the status
                    filesProcessed++;
                    actionTarget.setText("Deleting file " + filesProcessed + " of " + totalFileCount);

                    //Grab the file
                    File file = itr.next();

                    if (!file.delete()) {
                        JOptionPane.showMessageDialog(null, file.getPath() + " not deleted.");
                    }

                } catch (Exception except) {
                }
            } //End while

            actionTarget.setText("Deleted: " + filesProcessed);

        } else {
            actionTarget.setFill(Color.FIREBRICK);
            actionTarget.setText("Invalid directory.");
        }
    });

}

From source file:com.funambol.framework.tools.WBXMLToolsTest.java

/**
 * Test of wbxmlToXml and toWBXML methods, of class WBXMLTools.
 * @throws java.lang.Exception /*from   w w w  . j  ava 2s . c o m*/
 */
public void testWbxmlToXmlToWbxml() throws Exception {
    System.out.println("wbxmlToXml");
    Collection<File> files = FileUtils.listFiles(new File(WBXML_TO_XML_TO_WBXML_DIR), new String[] { "wbxml" },
            false);

    for (File f : files) {
        String fileNameWithExtension = f.getName();
        int indexExtension = fileNameWithExtension.indexOf(".wbxml");
        String fileName = fileNameWithExtension.substring(0, indexExtension);
        String xmlFileName = fileName + ".xml";
        testWbxmlToXmlToWbxml(f, new File(WBXML_TO_XML_TO_WBXML_DIR + xmlFileName));
    }

}

From source file:com.vmware.photon.controller.deployer.configuration.ServiceConfigurator.java

public void applyDynamicParameters(String mustacheDir, ContainersConfig.ContainerType containerType,
        final Map<String, ?> dynamicParameters) {
    File configDir = new File(mustacheDir, ServiceFileConstants.CONTAINER_CONFIG_ROOT_DIRS.get(containerType));
    Collection<File> files = FileUtils.listFiles(configDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    files.stream().forEach(file -> applyMustacheParameters(file, dynamicParameters));
}

From source file:com.textocat.textokit.commons.cpe.XmiCollectionReader.java

@Override
protected Iterable<Resource> getResources(UimaContext ctx) throws IOException, ResourceInitializationException {
    // if input directory does not exist or is not a directory, throw exception
    if (!inputDir.isDirectory()) {
        throw new ResourceInitializationException(ResourceConfigurationException.DIRECTORY_NOT_FOUND,
                new Object[] { PARAM_INPUTDIR, this.getMetaData().getName(), inputDir.getPath() });
    }//from w  w  w . j a va  2 s  .  c o  m
    // get list of .xmi files in the specified directory
    Collection<File> mFiles = FileUtils.listFiles(inputDir, suffixFileFilter(".xmi"), trueFileFilter());
    xmiResources = Collections2.transform(mFiles, PUtils.file2Resource);
    return xmiResources;
}

From source file:epgtools.dumpepgfromts.subtool.filelistmaker.FileSeeker.java

/**
 * ???????/*from  w  w  w. ja  v  a2  s  .  c o m*/
 *
 * @return ??????
 */
public synchronized List<File> seek() {

    List<File> list = Collections.synchronizedList(new ArrayList<File>());
    Collection<File> files = FileUtils.listFiles(this.SourceDir, this.fileType, this.dirf);
    list.addAll(files);
    return Collections.unmodifiableList(list);

}

From source file:com.aionemu.commons.services.ScriptService.java

/**
 * Loads all files from given directory//  ww  w. ja v a2 s.  co  m
 *
 * @param dir directory to scan for files
 */
private void loadDir(File dir) {
    for (Object file : FileUtils.listFiles(dir, new String[] { "xml" }, false)) {
        loadFile((File) file);
    }
}

From source file:com.freedomotic.plugins.devices.simulation.TrackingReadFile.java

@Override
public void onStart() throws PluginStartupException {
    try {/*  w  w w.j  a v a2  s .  c  om*/
        workers = new ArrayList<>();

        File dir = new File(Info.PATHS.PATH_DEVICES_FOLDER + "/simulation/data/motes");
        String[] extensions = new String[] { "mote" };
        LOG.info("Getting all \".mote\" files in \"{}\"", dir.getCanonicalPath());
        List<File> motes = (List<File>) FileUtils.listFiles(dir, extensions, true);
        if (!motes.isEmpty()) {
            for (File file : motes) {
                switch (DATA_TYPE) {
                case "coordinates":
                    readMoteFileCoordinates(file);
                    break;
                case "rooms":
                    readMoteFileRooms(file);
                    break;
                default:
                    throw new PluginStartupException("<data-type> property wrong in manifest file");
                }
            }
            for (WorkerThread workerThread : workers) {
                workerThread.start();
            }
        } else {
            throw new PluginStartupException("No \".mote\" files found.");
        }
    } catch (IOException ex) {
        throw new PluginStartupException("Error during file \".motes\" loading." + ex.getMessage(), ex);
    }
}

From source file:de.rub.syssec.saaf.Headless.java

/**
 * Gather APKs for option-cases file, directory and recursive directory.
 *
 * @param path      APK file or directory of multiple APKs
 * @return          LinkedList of APK-Files
 * /*from w ww  .ja  v  a  2  s.  c o  m*/
 */
private static LinkedList<File> gatherApksFromPath(File path) {
    LinkedList<File> apks = new LinkedList<File>();
    if (path.isDirectory()) {
        Collection<File> fc = FileUtils.listFiles(path, null,
                CONFIG.getBooleanConfigValue(ConfigKeys.RECURSIVE_DIR_ANALYSIS));
        apks = new LinkedList<File>(fc);
        if (apks.size() <= 0) {
            LOGGER.info("No files found in directory. Forgot a -r?");
        }
        LOGGER.info("Read " + apks.size() + " files from Directory " + path);
    } else if (path.isFile()) {
        apks.add(path);
    }
    return apks;
}