{"id":1732,"date":"2016-02-28T15:23:35","date_gmt":"2016-02-28T07:23:35","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=1732"},"modified":"2016-02-28T15:24:36","modified_gmt":"2016-02-28T07:24:36","slug":"enumerate-all-files-in-the-data-folder-of-processing","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2016\/02\/28\/enumerate-all-files-in-the-data-folder-of-processing\/","title":{"rendered":"Enumerate all files in the data folder of Processing"},"content":{"rendered":"<p>There are lots of ways to enumerate all the files inside the <strong>data<\/strong> folder of Processing sketch. Here are 2 of them. The first one uses the Java <a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/nio\/file\/DirectoryStream.html\">DirectoryStream<\/a> class. The second one uses the static function <strong>walkFileTree<\/strong> from the <a href=\"https:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/nio\/file\/Files.html\">Files<\/a> class.<br \/>\n&nbsp;<br \/>\n<em>Example with DirectoryStream<\/em><\/p>\n<pre lang=\"java\">\r\ntry {\r\n    DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(dataPath(\"\"))); \r\n    for (Path file : stream) {\r\n      println(file.getFileName());\r\n    }\r\n  } \r\n  catch (IOException e) {\r\n    e.printStackTrace();\r\n}\r\n<\/pre>\n<p><em>Example with Files.walkFileTree<\/em><\/p>\n<pre lang=\"java\">\r\ntry {\r\n    Files.walkFileTree(Paths.get(dataPath(\"\")), new SimpleFileVisitor<Path>() {\r\n      @Override\r\n        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {\r\n        println(file.getFileName());\r\n        return FileVisitResult.CONTINUE;\r\n      }\r\n    }\r\n    );\r\n  } \r\n  catch (IOException e) {\r\n    e.printStackTrace();\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are lots of ways to enumerate all the files inside the data folder of Processing sketch. Here are 2 of them. The first one uses the Java DirectoryStream class. The second one uses the static function walkFileTree from the Files class. &nbsp; Example with DirectoryStream try { DirectoryStream stream = Files.newDirectoryStream(Paths.get(dataPath(&#8220;&#8221;))); for (Path file [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79,66],"tags":[62],"class_list":["post-1732","post","type-post","status-publish","format-standard","hentry","category-software-2","category-testing","tag-processing-org"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1732","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/comments?post=1732"}],"version-history":[{"count":2,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1732\/revisions"}],"predecessor-version":[{"id":1734,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1732\/revisions\/1734"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=1732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=1732"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=1732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}