fix io.paths
parent
17c8846e9f
commit
f9661a4699
|
@ -1,14 +1,16 @@
|
|||
! Copyright (C) 2008 Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: io.files kernel sequences accessors
|
||||
dlists deques arrays sequences.lib ;
|
||||
dlists deques arrays ;
|
||||
IN: io.paths
|
||||
|
||||
TUPLE: directory-iterator path bfs queue ;
|
||||
|
||||
: qualified-directory ( path -- seq )
|
||||
dup directory [ first2 >r append-path r> 2array ] with map ;
|
||||
dup directory [ first2 [ append-path ] dip 2array ] with map ;
|
||||
|
||||
: push-directory ( path iter -- )
|
||||
>r qualified-directory r> [
|
||||
[ qualified-directory ] dip [
|
||||
dup queue>> swap bfs>>
|
||||
[ push-front ] [ push-back ] if
|
||||
] curry each ;
|
||||
|
@ -24,27 +26,24 @@ TUPLE: directory-iterator path bfs queue ;
|
|||
] if ;
|
||||
|
||||
: iterate-directory ( iter quot -- obj )
|
||||
2dup >r >r >r next-file dup [
|
||||
r> call dup [
|
||||
r> r> 2drop
|
||||
over next-file [
|
||||
over call
|
||||
[ 2drop ] [ iterate-directory ] if
|
||||
] [
|
||||
drop r> r> iterate-directory
|
||||
] if
|
||||
] [
|
||||
drop r> r> r> 3drop f
|
||||
] if ; inline
|
||||
2drop f
|
||||
] if* ; inline recursive
|
||||
|
||||
: find-file ( path bfs? quot -- path/f )
|
||||
>r <directory-iterator> r>
|
||||
[ <directory-iterator> ] dip
|
||||
[ keep and ] curry iterate-directory ; inline
|
||||
|
||||
: each-file ( path bfs? quot -- )
|
||||
>r <directory-iterator> r>
|
||||
[ <directory-iterator> ] dip
|
||||
[ f ] compose iterate-directory drop ; inline
|
||||
|
||||
: find-all-files ( path bfs? quot -- paths )
|
||||
>r <directory-iterator> r>
|
||||
pusher >r [ f ] compose iterate-directory drop r> ; inline
|
||||
[ <directory-iterator> ] dip
|
||||
pusher [ [ f ] compose iterate-directory drop ] dip ; inline
|
||||
|
||||
: recursive-directory ( path bfs? -- paths )
|
||||
[ ] accumulator >r each-file r> ;
|
||||
[ ] accumulator [ each-file ] dip ;
|
||||
|
|
Loading…
Reference in New Issue