diff --git a/basis/io/directories/search/search-docs.factor b/basis/io/directories/search/search-docs.factor new file mode 100644 index 0000000000..359f1796bb --- /dev/null +++ b/basis/io/directories/search/search-docs.factor @@ -0,0 +1,66 @@ +! Copyright (C) 2009 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: help.markup help.syntax kernel quotations ; +IN: io.directories.search + +HELP: each-file +{ $values + { "path" "a pathname string" } { "bfs?" "a boolean, breadth-first or depth-first" } { "quot" quotation } +} +{ $description "Performs a directory traversal, breadth-first or depth-first, and calls the quotation on the full pathname of each file." } +{ $examples + { $unchecked-example "USING: sequences io.directories.search ;" + "\"resource:misc\" t [ . ] each-file" + "! Recursive directory listing prints here" + } +} ; + +HELP: recursive-directory +{ $values + { "path" "a pathname string" } { "bfs?" "a boolean, breadth-first or depth-first" } + { "paths" "a sequence of pathname strings" } +} +{ $description "Traverses a directory path recursively and returns a sequence of files in a breadth-first or depth-first manner." } ; + +HELP: find-file +{ $values + { "path" "a pathname string" } { "bfs?" "a boolean, breadth-first or depth-first" } { "quot" quotation } + { "path/f" "a pathname string or f" } +} +{ $description "Finds the first file in the input directory matching the predicate quotation in a breadth-first or depth-first traversal." } ; + +HELP: find-in-directories +{ $values + { "directories" "a sequence of pathnames" } { "bfs?" "a boolean, breadth-first or depth-first" } { "quot" quotation } + { "path'" "a pathname string" } +} +{ $description "Finds the first file in the input directories matching the predicate quotation in a breadth-first or depth-first traversal." } ; + +HELP: find-all-files +{ $values + { "path" "a pathname string" } { "bfs?" "a boolean, breadth-first or depth-first" } { "quot" quotation } + { "paths" "a sequence of pathname strings" } +} +{ $description "Finds all files in the input directory matching the predicate quotation in a breadth-first or depth-first traversal." } ; + +HELP: find-all-in-directories +{ $values + { "directories" "a sequence of directory paths" } { "bfs?" "a boolean, breadth-first or depth-first" } { "quot" quotation } + { "paths" "a sequence of pathname strings" } +} +{ $description "Finds all files in the input directories matching the predicate quotation in a breadth-first or depth-first traversal." } ; + +{ find-file find-all-files find-in-directories find-all-in-directories } related-words + +ARTICLE: "io.directories.search" "io.directories.search" +"The " { $vocab-link "io.directories.search" } " vocabulary contains words used for recursively iterating over a directory and for finding files in a directory tree." $nl +"Traversing directories:" +{ $subsection recursive-directory } +{ $subsection each-file } +"Finding files:" +{ $subsection find-file } +{ $subsection find-all-files } +{ $subsection find-in-directories } +{ $subsection find-all-in-directories } ; + +ABOUT: "io.directories.search" diff --git a/basis/io/directories/search/search.factor b/basis/io/directories/search/search.factor index 137e919412..d1fdff34f9 100755 --- a/basis/io/directories/search/search.factor +++ b/basis/io/directories/search/search.factor @@ -5,10 +5,10 @@ io.directories io.files io.files.info io.pathnames kernel sequences system vocabs.loader ; IN: io.directories.search -TUPLE: directory-iterator path bfs queue ; - +: each-file ( path bfs? quot: ( obj -- ) -- ) + [ ] dip + [ f ] compose iterate-directory drop ; inline + +: recursive-directory ( path bfs? -- paths ) + [ ] accumulator [ each-file ] dip ; + : find-file ( path bfs? quot: ( obj -- ? ) -- path/f ) [ ] dip [ keep and ] curry iterate-directory ; inline -: each-file ( path bfs? quot: ( obj -- ? ) -- ) - [ ] dip - [ f ] compose iterate-directory drop ; inline - : find-all-files ( path bfs? quot: ( obj -- ? ) -- paths ) [ ] dip pusher [ [ f ] compose iterate-directory drop ] dip ; inline -: recursive-directory ( path bfs? -- paths ) - [ ] accumulator [ each-file ] dip ; +: find-in-directories ( directories bfs? quot: ( obj -- ? ) -- path' ) + '[ _ _ find-file ] attempt-all ; -: find-in-directories ( directories bfs? quot -- path' ) - '[ _ _ find-file ] attempt-all ; inline +: find-all-in-directories ( directories bfs? quot: ( obj -- ? ) -- paths ) + '[ _ _ find-all-files ] map concat ; os windows? [ "io.directories.search.windows" require ] when