From cf3ccd0abec18cc6aebc66b9e1f1f96899eba0f8 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 21 May 2015 22:34:55 -0700 Subject: [PATCH] io.directories.search: Add some more combinators for finding files. --- basis/io/directories/search/search.factor | 30 ++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/basis/io/directories/search/search.factor b/basis/io/directories/search/search.factor index 056347ec5f..4357e5cd8c 100644 --- a/basis/io/directories/search/search.factor +++ b/basis/io/directories/search/search.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs continuations deques dlists fry io.backend io.directories io.files.info io.pathnames kernel -kernel.private locals math sequences sorting strings system -unicode.case vocabs vocabs.loader ; +kernel.private locals math sequences sequences.extras sorting +strings system unicode.case vocabs ; IN: io.directories.search : qualified-directory-entries ( path -- seq ) @@ -63,9 +63,27 @@ TUPLE: directory-iterator PRIVATE> -: each-file ( path bfs? quot: ( ... name -- ... ) -- ) +: each-file ( path bfs? quot -- ) setup-traversal iterate-directory drop ; inline +: each-file-breadth ( path quot -- ) + t swap each-file ; inline + +: each-file-depth ( path quot -- ) + f swap each-file ; inline + +: filter-files-by-depth ( quot -- seq ) + selector* [ each-file-depth ] dip ; inline + +: filter-files-by-breadth ( quot -- seq ) + selector* [ each-file-breadth ] dip ; inline + +: all-files-by-depth ( quot -- seq ) + collector [ each-file-depth ] dip ; inline + +: all-files-by-breadth ( quot -- seq ) + collector [ each-file-breadth ] dip ; inline + : each-directory-entry ( path bfs? quot: ( ... entry -- ... ) -- ) setup-traversal iterate-directory-entries drop ; inline @@ -147,4 +165,10 @@ ERROR: sequence-expected obj ; : find-by-extension ( path extension -- seq ) 1array find-by-extensions ; +: find-files-larger-than ( path size -- seq ) + '[ file-info size>> _ > ] filter-files-by-depth ; + +: file-info-recursive ( path -- seq ) + [ dup ?file-info [ 2array ] [ drop f ] if* ] filter-files-by-depth ; + os windows? [ "io.directories.search.windows" require ] when