1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax kernel quotations sequences ;
4 IN: io.directories.search
8 { "path" "a pathname string" } { "bfs?" "a boolean, breadth-first or depth-first" } { "quot" quotation }
10 { $description "Performs a directory traversal, breadth-first or depth-first, and calls the quotation on the full pathname of each file." }
12 { $unchecked-example "USING: sequences io.directories.search ;"
13 "\"resource:misc\" t [ . ] each-file"
14 "! Recursive directory listing prints here"
18 HELP: recursive-directory-files
20 { "path" "a pathname string" } { "bfs?" "a boolean, breadth-first or depth-first" }
21 { "paths" "a sequence of pathname strings" }
23 { $description "Traverses a directory path recursively and returns a sequence of files in a breadth-first or depth-first manner." } ;
25 HELP: recursive-directory-entries
27 { "path" "a pathname string" } { "bfs?" "a boolean, breadth-first or depth-first" }
28 { "directory-entries" "a sequence of directory-entries" }
30 { $description "Traverses a directory path recursively and returns a sequence of directory-entries in a breadth-first or depth-first manner." } ;
34 { "path" "a pathname string" } { "bfs?" "a boolean, breadth-first or depth-first" } { "quot" quotation }
35 { "path/f" "a pathname string or f" }
37 { $description "Finds the first file in the input directory matching the predicate quotation in a breadth-first or depth-first traversal." } ;
39 HELP: find-in-directories
41 { "directories" "a sequence of pathnames" } { "bfs?" "a boolean, breadth-first or depth-first" } { "quot" quotation }
42 { "path'/f" "a pathname string or f" }
44 { $description "Finds the first file in the input directories matching the predicate quotation in a breadth-first or depth-first traversal." } ;
48 { "path" "a pathname string" } { "quot" quotation }
49 { "paths/f" "a sequence of pathname strings or f" }
51 { $description "Recursively finds all files in the input directory matching the predicate quotation." } ;
53 HELP: find-all-in-directories
55 { "directories" "a sequence of directory paths" } { "quot" quotation }
56 { "paths/f" "a sequence of pathname strings or f" }
58 { $description "Finds all files in the input directories matching the predicate quotation in a breadth-first or depth-first traversal." } ;
60 HELP: find-by-extension
62 { "path" "a pathname string" } { "extension" "a file extension" }
65 { $description "Searches a directory for all files with the given extension. File extension and filenames are converted to lower-case and compared using the " { $link tail? } " word. The file extension should contain the period." }
68 "USING: io.directories.search ;"
69 "\"/\" \".mp3\" find-by-extension"
73 HELP: find-by-extensions
75 { "path" "a pathname string" } { "extensions" "a sequence of file extensions" }
78 { $description "Searches a directory for all files in the given list of extensions. File extensions and filenames are converted to lower-case and compared using the " { $link tail? } " word. File extensions should contain the period." }
81 "USING: io.directories.search ;"
82 "\"/\" { \".jpg\" \".gif\" \".tiff\" \".png\" \".bmp\" } find-by-extensions"
86 { find-file find-all-files find-in-directories find-all-in-directories } related-words
88 ARTICLE: "io.directories.search" "Searching directories"
89 "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
90 "Traversing directories:"
91 { $subsection recursive-directory-files }
92 { $subsection recursive-directory-entries }
93 { $subsection each-file }
94 "Finding files by name:"
95 { $subsection find-file }
96 { $subsection find-all-files }
97 { $subsection find-in-directories }
98 { $subsection find-all-in-directories }
99 "Finding files by extension:"
100 { $subsection find-by-extension }
101 { $subsection find-by-extensions } ;
103 ABOUT: "io.directories.search"