Example usage for java.io FilenameFilter FilenameFilter

List of usage examples for java.io FilenameFilter FilenameFilter

Introduction

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

Prototype

FilenameFilter

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    File f = new File("c:/test");
    FilenameFilter fileNameFilter = new FilenameFilter() {
        @Override/*from ww w  .ja v  a 2s .c o  m*/
        public boolean accept(File dir, String name) {
            if (name.lastIndexOf('.') > 0) {
                int lastIndex = name.lastIndexOf('.');
                String str = name.substring(lastIndex);
                if (str.equals(".txt")) {
                    return true;
                }
            }
            return false;
        }
    };
    File[] paths = f.listFiles(fileNameFilter);
    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");
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return !name.startsWith(".");
        }//from   w ww  .j a  v  a 2  s  .  c o m
    };
    String[] children = dir.list(filter);

}

From source file:Main.java

public static void main(String[] args) {
    File directory = new File("c:\\");

    if (!directory.isDirectory()) {
        System.out.println("No directory provided");
        return;//from  ww  w. j  av  a2s. co  m
    }

    FilenameFilter filefilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".txt");
        }
    };

    String[] filenames = directory.list(filefilter);

    for (String name : filenames) {
        System.out.println(name);
    }
}

From source file:MainClass.java

public static void main(final String[] args) {
    File path = new File(".");
    String[] list;/* ww w.  ja va2s. co m*/
    if (args.length == 0)
        list = path.list();
    else
        list = path.list(new FilenameFilter() {
            private Pattern pattern = Pattern.compile(args[0]);

            public boolean accept(File dir, String name) {
                return pattern.matcher(new File(name).getName()).matches();
            }
        });
    Arrays.sort(list);
    for (int i = 0; i < list.length; i++)
        System.out.println(list[i]);
}

From source file:Main.java

public static void main(String[] args) {
    File games = new File("C:\\Test");
    File[] files = games.listFiles();
    for (File file : files) {
        System.out.println(file + " is a " + (file.isDirectory() ? "directory" : "file"));
    }/*from w  ww  . j  av a  2  s.c o m*/
    String[] xfiles = games.list();
    for (String file : xfiles) {
        System.out.println("File = " + file);
    }
    FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            if (name.endsWith(".txt")) {
                return true;
            }
            return false;
        }
    };

    File[] yfiles = games.listFiles(filter);
    for (File doc : yfiles) {
        System.out.println("Doc file = " + doc);
    }
}

From source file:DirList3.java

public static void main(final String[] args) {
    File path = new File(".");
    String[] list;//w  w w. j  av  a2s .  co m
    if (args.length == 0)
        list = path.list();
    else
        list = path.list(new FilenameFilter() {
            private Pattern pattern = Pattern.compile(args[0]);

            public boolean accept(File dir, String name) {
                return pattern.matcher(new File(name).getName()).matches();
            }
        });
    Arrays.sort(list, new AlphabeticComparator());
    for (int i = 0; i < list.length; i++)
        System.out.println(list[i]);
}

From source file:com.github.rinde.gpem17.Train.java

public static void main(String[] args) {
    if (args.length == 0) {
        run("files/config/gpem17.params");
    } else {//  w  w  w  .  j a v  a  2s .com
        for (String file : args) {
            File f = new File(file);
            if (f.isDirectory()) {
                File[] paramFiles = f.listFiles(new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                        return name.endsWith(".params");
                    }
                });

                Arrays.sort(paramFiles, new Comparator<File>() {
                    @Override
                    public int compare(File o1, File o2) {
                        return o1.getName().compareTo(o2.getName());
                    }
                });

                for (File paramFile : paramFiles) {
                    run(paramFile.getPath());
                }
            } else {
                run(file);
            }
        }
    }
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.clustering.ClusterCentroidsMain.java

public static void main(String[] args) throws Exception {
    //        String clutoVectors = args[0];
    //        String clutoOuputClusters = args[1];
    //        String outputClusterCentroids = args[2];

    File[] files = new File("//home/user-ukp/data2/debates-ranked.100-xmi").listFiles(new FilenameFilter() {
        @Override/*  w w w .  ja  v  a2s.  co  m*/
        public boolean accept(File dir, String name) {
            //                        return name.startsWith("arg") && name.endsWith(".mat");
            return name.startsWith("sent") && name.endsWith(".mat");
        }
    });
    for (File matFile : files) {
        String clutoVectors = matFile.getAbsolutePath();
        //            String clutoOuputClusters = matFile.getAbsolutePath() + ".clustering.100";
        String clutoOuputClusters = matFile.getAbsolutePath() + ".clustering.1000";
        String outputClusterCentroids = matFile.getAbsolutePath() + ".bin";

        TreeMap<Integer, Vector> centroids = computeClusterCentroids(clutoVectors, clutoOuputClusters);

        // and serialize
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(
                new FileOutputStream(outputClusterCentroids));
        objectOutputStream.writeObject(centroids);
        IOUtils.closeQuietly(objectOutputStream);
    }

    //        System.out.println(centroids);
    //        embeddingsToDistance(args[0], centroids, args[2]);
}

From source file:de.fatalix.book.importer.CalibriImporter.java

public static void main(String[] args) throws IOException, URISyntaxException, SolrServerException {
    Gson gson = new Gson();
    CalibriImporterConfiguration config = gson.fromJson(args[0], CalibriImporterConfiguration.class);
    File importFolder = new File(config.getImportFolder());
    if (importFolder.isDirectory()) {
        File[] zipFiles = importFolder.listFiles(new FilenameFilter() {

            @Override/*w  w  w .j  av a 2s .  c  om*/
            public boolean accept(File dir, String name) {
                return name.endsWith(".zip");
            }
        });
        for (File zipFile : zipFiles) {
            try {
                processBooks(zipFile.toPath(), config.getSolrCore(), config.getSolrCore(),
                        config.getBatchSize());
                System.out.println("Processed file " + zipFile.getName());
            } catch (IOException ex) {
                ex.printStackTrace();

            }
        }
    } else {
        System.out.println("Import folder: " + importFolder.getAbsolutePath() + " cannot be read!");
    }
}

From source file:edu.cornell.med.icb.goby.util.RenameWeights.java

public static void main(final String[] args) throws IOException {
    final File directory = new File(".");

    final String[] list = directory.list(new FilenameFilter() {
        public boolean accept(final File directory, final String filename) {

            final String extension = FilenameUtils.getExtension(filename);
            return (extension.equals("entries"));
        }/*  www .  ja va  2s  . co  m*/
    });
    for (final String filename : args) {
        final String extension = FilenameUtils.getExtension(filename);
        final String basename = FilenameUtils.removeExtension(filename);
        for (final String alignFilename : list) {
            final String alignBasename = FilenameUtils.removeExtension(alignFilename);
            if (alignBasename.endsWith(basename)) {
                System.out.println("move " + filename + " to " + alignBasename + "." + extension);

                final File destination = new File(alignBasename + "." + extension);
                FileUtils.deleteQuietly(destination);
                FileUtils.moveFile(new File(filename), destination);
            }
        }

    }
}