io.directories: move directory-tree-files words to io.directories.hierarchy, where all the other *-tree stuff is
parent
590586e551
commit
f3b264522c
|
@ -46,17 +46,21 @@ HELP: directory-files
|
|||
{ $values { "path" "a pathname string" } { "seq" "a sequence of filenames" } }
|
||||
{ $description "Outputs the contents of a directory named by " { $snippet "path" } "." } ;
|
||||
|
||||
HELP: directory-tree-files
|
||||
{ $values { "path" "a pathname string" } { "seq" "a sequence of filenames" } }
|
||||
{ $description "Outputs a sequence of all files and subdirectories inside the directory named by " { $snippet "path" } " or recursively inside its subdirectories." } ;
|
||||
|
||||
HELP: with-directory-files
|
||||
{ $values { "path" "a pathname string" } { "quot" quotation } }
|
||||
{ $description "Calls the quotation with the directory file names on the stack and with the directory set as the " { $link current-directory } ". Restores the current directory after the quotation is called." } ;
|
||||
|
||||
HELP: with-directory-tree-files
|
||||
{ $values { "path" "a pathname string" } { "quot" quotation } }
|
||||
{ $description "Calls the quotation with the recursive directory file names on the stack and with the directory set as the " { $link current-directory } ". Restores the current directory after the quotation is called." } ;
|
||||
{ $description "Calls the quotation with the directory file names on the stack and with the directory set as the " { $link current-directory } ". Restores the current directory after the quotation is called." }
|
||||
{ $examples
|
||||
"Print all files in your home directory which are larger than a megabyte:"
|
||||
{ $code
|
||||
"""USING: io.directoies io.files.info io.pathnames ;
|
||||
home [
|
||||
[
|
||||
dup link-info size>> 20 2^ >
|
||||
[ print ] [ drop ] if
|
||||
] each
|
||||
] with-directory-files"""
|
||||
}
|
||||
} ;
|
||||
|
||||
HELP: with-directory-entries
|
||||
{ $values { "path" "a pathname string" } { "quot" quotation } }
|
||||
|
|
|
@ -22,24 +22,6 @@ IN: io.directories.tests
|
|||
] with-directory-files
|
||||
] unit-test
|
||||
|
||||
[ { "classes/tuple/tuple.factor" } ] [
|
||||
"resource:core" [
|
||||
"." directory-tree-files [ "classes/tuple/tuple.factor" = ] filter
|
||||
] with-directory
|
||||
] unit-test
|
||||
|
||||
[ { "classes/tuple" } ] [
|
||||
"resource:core" [
|
||||
"." directory-tree-files [ "classes/tuple" = ] filter
|
||||
] with-directory
|
||||
] unit-test
|
||||
|
||||
[ { "classes/tuple/tuple.factor" } ] [
|
||||
"resource:core" [
|
||||
[ "classes/tuple/tuple.factor" = ] filter
|
||||
] with-directory-tree-files
|
||||
] unit-test
|
||||
|
||||
[ ] [ "blahblah" temp-file dup exists? [ delete-directory ] [ drop ] if ] unit-test
|
||||
[ ] [ "blahblah" temp-file make-directory ] unit-test
|
||||
[ t ] [ "blahblah" temp-file file-info directory? ] unit-test
|
||||
|
|
|
@ -37,30 +37,16 @@ HOOK: (directory-entries) os ( path -- seq )
|
|||
normalize-path
|
||||
(directory-entries)
|
||||
[ name>> { "." ".." } member? not ] filter ;
|
||||
|
||||
|
||||
: directory-files ( path -- seq )
|
||||
directory-entries [ name>> ] map ;
|
||||
|
||||
: directory-tree-files ( path -- seq )
|
||||
dup directory-entries
|
||||
[
|
||||
dup type>> +directory+ =
|
||||
[ name>>
|
||||
[ append-path directory-tree-files ]
|
||||
[ [ prepend-path ] curry map ]
|
||||
[ prefix ] tri
|
||||
] [ nip name>> 1array ] if
|
||||
] with map concat ;
|
||||
|
||||
: with-directory-entries ( path quot -- )
|
||||
'[ "" directory-entries @ ] with-directory ; inline
|
||||
|
||||
: with-directory-files ( path quot -- )
|
||||
'[ "" directory-files @ ] with-directory ; inline
|
||||
|
||||
: with-directory-tree-files ( path quot -- )
|
||||
'[ "" directory-tree-files @ ] with-directory ; inline
|
||||
|
||||
! Touching files
|
||||
HOOK: touch-file io-backend ( path -- )
|
||||
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
USING: help.markup help.syntax ;
|
||||
USING: help.markup help.syntax quotations io.pathnames ;
|
||||
IN: io.directories.hierarchy
|
||||
|
||||
HELP: directory-tree-files
|
||||
{ $values { "path" "a pathname string" } { "seq" "a sequence of filenames" } }
|
||||
{ $description "Outputs a sequence of all files and subdirectories inside the directory named by " { $snippet "path" } " or recursively inside its subdirectories." } ;
|
||||
|
||||
HELP: with-directory-tree-files
|
||||
{ $values { "path" "a pathname string" } { "quot" quotation } }
|
||||
{ $description "Calls the quotation with the recursive directory file names on the stack and with the directory set as the " { $link current-directory } ". Restores the current directory after the quotation is called." } ;
|
||||
|
||||
HELP: delete-tree
|
||||
{ $values { "path" "a pathname string" } }
|
||||
{ $description "Deletes a file or directory, recursing into subdirectories." }
|
||||
|
@ -31,6 +39,11 @@ $nl
|
|||
{ "Words named " { $snippet { $emphasis "operation" } "-file" } " which work on regular files only." }
|
||||
{ "Words named " { $snippet { $emphasis "operation" } "-tree" } " works on directory trees recursively, and also accepts regular files." }
|
||||
}
|
||||
"Listing directory trees recursively:"
|
||||
{ $subsections
|
||||
directory-tree-files
|
||||
with-directory-tree-files
|
||||
}
|
||||
"Deleting directory trees recursively:"
|
||||
{ $subsections delete-tree }
|
||||
"Copying directory trees recursively:"
|
||||
|
|
|
@ -1,10 +1,24 @@
|
|||
! Copyright (C) 2004, 2008 Slava Pestov, Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel accessors sequences combinators fry io.directories
|
||||
io.pathnames io.files.info io.files.types io.files.links
|
||||
io.backend ;
|
||||
USING: accessors arrays kernel sequences combinators fry
|
||||
io.directories io.pathnames io.files.info io.files.types
|
||||
io.files.links io.backend ;
|
||||
IN: io.directories.hierarchy
|
||||
|
||||
: directory-tree-files ( path -- seq )
|
||||
dup directory-entries
|
||||
[
|
||||
dup type>> +directory+ =
|
||||
[ name>>
|
||||
[ append-path directory-tree-files ]
|
||||
[ [ prepend-path ] curry map ]
|
||||
[ prefix ] tri
|
||||
] [ nip name>> 1array ] if
|
||||
] with map concat ;
|
||||
|
||||
: with-directory-tree-files ( path quot -- )
|
||||
'[ "" directory-tree-files @ ] with-directory ; inline
|
||||
|
||||
: delete-tree ( path -- )
|
||||
dup link-info directory? [
|
||||
[ [ [ delete-tree ] each ] with-directory-files ]
|
||||
|
@ -28,4 +42,3 @@ DEFER: copy-tree-into
|
|||
|
||||
: copy-trees-into ( files to -- )
|
||||
'[ _ copy-tree-into ] each ;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
! (c)2010 Joe Groff bsd license
|
||||
USING: arrays fry globs io.directories io.files.info
|
||||
io.pathnames kernel regexp sequences vocabs.loader
|
||||
USING: arrays fry globs io.directories io.directories.hierarchy
|
||||
io.files.info io.pathnames kernel regexp sequences vocabs.loader
|
||||
vocabs.metadata ;
|
||||
IN: vocabs.metadata.resources
|
||||
|
||||
|
|
Loading…
Reference in New Issue