Fix typo in each-file stack effect, document io.directories.search
							parent
							
								
									ffe0aac310
								
							
						
					
					
						commit
						e83713d557
					
				|  | @ -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" | ||||||
|  | @ -5,10 +5,10 @@ io.directories io.files io.files.info io.pathnames kernel | ||||||
| sequences system vocabs.loader ; | sequences system vocabs.loader ; | ||||||
| IN: io.directories.search | IN: io.directories.search | ||||||
| 
 | 
 | ||||||
| TUPLE: directory-iterator path bfs queue ; |  | ||||||
| 
 |  | ||||||
| <PRIVATE | <PRIVATE | ||||||
| 
 | 
 | ||||||
|  | TUPLE: directory-iterator path bfs queue ; | ||||||
|  | 
 | ||||||
| : qualified-directory ( path -- seq ) | : qualified-directory ( path -- seq ) | ||||||
|     dup directory-files [ append-path ] with map ; |     dup directory-files [ append-path ] with map ; | ||||||
| 
 | 
 | ||||||
|  | @ -38,22 +38,25 @@ TUPLE: directory-iterator path bfs queue ; | ||||||
| 
 | 
 | ||||||
| PRIVATE> | PRIVATE> | ||||||
| 
 | 
 | ||||||
|  | : each-file ( path bfs? quot: ( obj -- ) -- ) | ||||||
|  |     [ <directory-iterator> ] dip | ||||||
|  |     [ f ] compose iterate-directory drop ; inline | ||||||
|  | 
 | ||||||
|  | : recursive-directory ( path bfs? -- paths ) | ||||||
|  |     [ ] accumulator [ each-file ] dip ; | ||||||
|  | 
 | ||||||
| : find-file ( path bfs? quot: ( obj -- ? ) -- path/f ) | : find-file ( path bfs? quot: ( obj -- ? ) -- path/f ) | ||||||
|     [ <directory-iterator> ] dip |     [ <directory-iterator> ] dip | ||||||
|     [ keep and ] curry iterate-directory ; inline |     [ keep and ] curry iterate-directory ; inline | ||||||
| 
 | 
 | ||||||
| : each-file ( path bfs? quot: ( obj -- ? ) -- ) |  | ||||||
|     [ <directory-iterator> ] dip |  | ||||||
|     [ f ] compose iterate-directory drop ; inline |  | ||||||
| 
 |  | ||||||
| : find-all-files ( path bfs? quot: ( obj -- ? ) -- paths ) | : find-all-files ( path bfs? quot: ( obj -- ? ) -- paths ) | ||||||
|     [ <directory-iterator> ] dip |     [ <directory-iterator> ] dip | ||||||
|     pusher [ [ f ] compose iterate-directory drop ] dip ; inline |     pusher [ [ f ] compose iterate-directory drop ] dip ; inline | ||||||
| 
 | 
 | ||||||
| : recursive-directory ( path bfs? -- paths ) | : find-in-directories ( directories bfs? quot: ( obj -- ? ) -- path' ) | ||||||
|     [ ] accumulator [ each-file ] dip ; |     '[ _ _ find-file ] attempt-all ; | ||||||
| 
 | 
 | ||||||
| : find-in-directories ( directories bfs? quot -- path' ) | : find-all-in-directories ( directories bfs? quot: ( obj -- ? ) -- paths ) | ||||||
|     '[ _ _ find-file ] attempt-all ; inline |     '[ _ _ find-all-files ] map concat ; | ||||||
| 
 | 
 | ||||||
| os windows? [ "io.directories.search.windows" require ] when | os windows? [ "io.directories.search.windows" require ] when | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue