List of usage examples for java.nio.file Files walkFileTree
public static Path walkFileTree(Path start, FileVisitor<? super Path> visitor) throws IOException
From source file:Test.java
public static void main(String[] args) throws IOException { Path startingDir = Paths.get("/Users/java"); Files.walkFileTree(startingDir, new FindJavaVisitor()); }
From source file:Main.java
public static void main(String[] args) { Path startDir = Paths.get(""); FileVisitor<Path> visitor = getFileVisitor(); try {//from w ww.j a v a2 s . co m Files.walkFileTree(startDir, visitor); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { Path dirToDelete = Paths.get("DIR"); FileVisitor<Path> visitor = getFileVisitor(); try {//from w w w . j ava 2 s . co m Files.walkFileTree(dirToDelete, visitor); } catch (IOException e) { System.out.println(e.getMessage()); } }
From source file:DeleteDirectory.java
public static void main(String[] args) { try {/*from ww w . j av a 2 s.c o m*/ Files.walkFileTree(Paths.get("/home"), new DeleteDirectory()); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:ListFiles.java
public static void main(String[] args) { try {//from ww w . j ava 2 s . com Path path = Paths.get("/home"); ListFiles listFiles = new ListFiles(); Files.walkFileTree(path, listFiles); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:org.hbz.oerworldmap.BuildMembershipReziprocally.java
public static void main(String... args) throws FileNotFoundException, IOException { concordance.put("b87cd10f-c537-499c-803c-c15bdb76a15c", "ocwc408"); concordance.put("0d3c90a8-20fd-412e-8ea8-8640d4571c09", "ocwc215"); concordance.put("ba48e2ff-6851-4c12-9a37-d4fa3594fbe6", "ocwc577"); concordance.put("ee479855-3c03-47c4-b256-1b35f78da110", "ocwc370"); concordance.put("03d57204-3215-4a7e-9132-a3411a8f4ee0", "ocwc262"); concordance.put("95308f8c-bea0-46d0-8b61-bf39566c6e22", "ocwc213"); concordance.put("cd613b01-a235-4a92-83fc-014728f1da66", "ocwc214"); TripleCrawler crawler = new TripleCrawler(); if (args.length >= 1) { PATH = args[0];//from w w w.ja v a 2 s.co m } Files.walkFileTree(Paths.get(PATH), crawler); process(crawler.data); }
From source file:com.datazuul.iiif.presentation.api.ManifestGenerator.java
public static void main(String[] args) throws ParseException, JsonProcessingException, IOException, URISyntaxException { Options options = new Options(); options.addOption("d", true, "Absolute file path to the directory containing the image files."); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("d")) { String imageDirectoryPath = cmd.getOptionValue("d"); Path imageDirectory = Paths.get(imageDirectoryPath); final List<Path> files = new ArrayList<>(); try {// w ww.j a va2 s. c om Files.walkFileTree(imageDirectory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!attrs.isDirectory()) { // TODO there must be a more elegant solution for filtering jpeg files... if (file.getFileName().toString().endsWith("jpg")) { files.add(file); } } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { e.printStackTrace(); } Collections.sort(files, new Comparator() { @Override public int compare(Object fileOne, Object fileTwo) { String filename1 = ((Path) fileOne).getFileName().toString(); String filename2 = ((Path) fileTwo).getFileName().toString(); try { // numerical sorting Integer number1 = Integer.parseInt(filename1.substring(0, filename1.lastIndexOf("."))); Integer number2 = Integer.parseInt(filename2.substring(0, filename2.lastIndexOf("."))); return number1.compareTo(number2); } catch (NumberFormatException nfe) { // alpha-numerical sorting return filename1.compareToIgnoreCase(filename2); } } }); generateManifest(imageDirectory.getFileName().toString(), files); } else { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ManifestGenerator", options); } }
From source file:controllers.oer.NtToEs.java
public static void main(String... args) throws ElasticsearchException, FileNotFoundException, IOException { if (args.length != 1 && args.length != 2) { System.out.println("Pass the root directory to crawl. " + "Will recursively gather all content from *.nt " + "files with identical names, convert these to " + "compact JSON-LD and index it in ES. " + "If a second argument is passed it is processed " + "as a TSV file that maps file names (w/o " + "extensions) to IDs to be used for ES. Else the " + "file names (w/o extensions) are used."); args = new String[] { "../oer-data/tmp", "../oer-data/src/main/resources/internalId2uuid.tsv" }; System.out.println("Using defaults: " + Arrays.asList(args)); }/*w w w.ja v a 2s . co m*/ if (args.length == 2) initMap(args[1]); TripleCrawler crawler = new TripleCrawler(); Files.walkFileTree(Paths.get(args[0]), crawler); createIndex(config(), INDEX); process(crawler.data); }
From source file:mcnutty.music.get.MusicGet.java
public static void main(String[] args) throws Exception { //print out music-get System.out.println(" _ _ "); System.out.println(" _ __ ___ _ _ ___(_) ___ __ _ ___| |_ "); System.out.println("| '_ ` _ \\| | | / __| |/ __|____ / _` |/ _ \\ __|"); System.out.println("| | | | | | |_| \\__ \\ | (_|_____| (_| | __/ |_ "); System.out.println("|_| |_| |_|\\__,_|___/_|\\___| \\__, |\\___|\\__|"); System.out.println(" |___/ \n"); //these will always be initialised later (but the compiler doesn't know that) String directory = ""; Properties prop = new Properties(); try (InputStream input = new FileInputStream("config.properties")) { prop.load(input);/*from w w w .j a va 2 s .c o m*/ if (prop.getProperty("directory") != null) { directory = prop.getProperty("directory"); } else { System.out.println( "Error reading config property 'directory' - using default value of /tmp/musicserver/\n"); directory = "/tmp/musicserver/"; } if (prop.getProperty("password") == null) { System.out.println("Error reading config property 'password' - no default value, exiting\n"); System.exit(1); } } catch (IOException e) { System.out.println("Error reading config file"); System.exit(1); } //create a queue object ProcessQueue process_queue = new ProcessQueue(); try { if (args.length > 0 && args[0].equals("clean")) { Files.delete(Paths.get("queue.json")); } //load an existing queue if possible String raw_queue = Files.readAllLines(Paths.get("queue.json")).toString(); JSONArray queue_state = new JSONArray(raw_queue); ConcurrentLinkedQueue<QueueItem> loaded_queue = new ConcurrentLinkedQueue<>(); JSONArray queue = queue_state.getJSONArray(0); for (int i = 0; i < queue.length(); i++) { JSONObject item = ((JSONObject) queue.get(i)); QueueItem loaded_item = new QueueItem(); loaded_item.ip = item.getString("ip"); loaded_item.real_name = item.getString("name"); loaded_item.disk_name = item.getString("guid"); loaded_queue.add(loaded_item); } process_queue.bucket_queue = loaded_queue; System.out.println("Loaded queue from disk\n"); } catch (Exception ex) { //otherwise clean out the music directory and start a new queue try { Files.walkFileTree(Paths.get(directory), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } }); Files.delete(Paths.get(directory)); } catch (Exception e) { e.printStackTrace(); } Files.createDirectory(Paths.get(directory)); System.out.println("Created a new queue\n"); } //start the web server StartServer start_server = new StartServer(process_queue, directory); new Thread(start_server).start(); //wit for the web server to spool up Thread.sleep(1000); //read items from the queue and play them while (true) { QueueItem next_item = process_queue.next_item(); if (!next_item.equals(new QueueItem())) { //Check the timeout int timeout = 547; try (FileInputStream input = new FileInputStream("config.properties")) { prop.load(input); timeout = Integer.parseInt(prop.getProperty("timeout", "547")); } catch (Exception e) { e.printStackTrace(); } System.out.println("Playing " + next_item.real_name); process_queue.set_played(next_item); process_queue.save_queue(); Process p = Runtime.getRuntime().exec("timeout " + timeout + "s mplayer -fs -quiet -af volnorm=2:0.25 " + directory + next_item.disk_name); try { p.waitFor(timeout, TimeUnit.SECONDS); Files.delete(Paths.get(directory + next_item.disk_name)); } catch (Exception e) { e.printStackTrace(); } } else { process_queue.bucket_played.clear(); } Thread.sleep(1000); } }
From source file:org.hbz.oerworldmap.NtToEs.java
public static void main(String... args) throws FileNotFoundException, IOException { if (args.length != 1 && args.length != 2) { System.out.println("Pass the root directory to crawl. " + "Will recursively gather all content from *.nt " + "files with identical names, convert these to " + "compact JSON-LD and index it in ES. " + "If a second argument is passed it is processed " + "as a TSV file that maps file names (w/o " + "extensions) to IDs to be used for ES. Else the " + "file names (w/o extensions) are used."); args = new String[] { "output", "src/main/resources/internalId2uuid.tsv" }; System.out.println("Using defaults: " + Arrays.asList(args)); }/* ww w . j av a 2s . c om*/ if (args.length == 2) initMap(args[1]); TripleCrawler crawler = new TripleCrawler(); Files.walkFileTree(Paths.get(args[0]), crawler); createIndex(config(), INDEX); process(crawler.data); }