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" } }
|
{ $values { "path" "a pathname string" } { "seq" "a sequence of filenames" } }
|
||||||
{ $description "Outputs the contents of a directory named by " { $snippet "path" } "." } ;
|
{ $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
|
HELP: with-directory-files
|
||||||
{ $values { "path" "a pathname string" } { "quot" quotation } }
|
{ $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." } ;
|
{ $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
|
||||||
HELP: with-directory-tree-files
|
"Print all files in your home directory which are larger than a megabyte:"
|
||||||
{ $values { "path" "a pathname string" } { "quot" quotation } }
|
{ $code
|
||||||
{ $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." } ;
|
"""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
|
HELP: with-directory-entries
|
||||||
{ $values { "path" "a pathname string" } { "quot" quotation } }
|
{ $values { "path" "a pathname string" } { "quot" quotation } }
|
||||||
|
|
|
@ -22,24 +22,6 @@ IN: io.directories.tests
|
||||||
] with-directory-files
|
] with-directory-files
|
||||||
] unit-test
|
] 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 dup exists? [ delete-directory ] [ drop ] if ] unit-test
|
||||||
[ ] [ "blahblah" temp-file make-directory ] unit-test
|
[ ] [ "blahblah" temp-file make-directory ] unit-test
|
||||||
[ t ] [ "blahblah" temp-file file-info directory? ] unit-test
|
[ t ] [ "blahblah" temp-file file-info directory? ] unit-test
|
||||||
|
|
|
@ -41,26 +41,12 @@ HOOK: (directory-entries) os ( path -- seq )
|
||||||
: directory-files ( path -- seq )
|
: directory-files ( path -- seq )
|
||||||
directory-entries [ name>> ] map ;
|
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 -- )
|
: with-directory-entries ( path quot -- )
|
||||||
'[ "" directory-entries @ ] with-directory ; inline
|
'[ "" directory-entries @ ] with-directory ; inline
|
||||||
|
|
||||||
: with-directory-files ( path quot -- )
|
: with-directory-files ( path quot -- )
|
||||||
'[ "" directory-files @ ] with-directory ; inline
|
'[ "" directory-files @ ] with-directory ; inline
|
||||||
|
|
||||||
: with-directory-tree-files ( path quot -- )
|
|
||||||
'[ "" directory-tree-files @ ] with-directory ; inline
|
|
||||||
|
|
||||||
! Touching files
|
! Touching files
|
||||||
HOOK: touch-file io-backend ( path -- )
|
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
|
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
|
HELP: delete-tree
|
||||||
{ $values { "path" "a pathname string" } }
|
{ $values { "path" "a pathname string" } }
|
||||||
{ $description "Deletes a file or directory, recursing into subdirectories." }
|
{ $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" } "-file" } " which work on regular files only." }
|
||||||
{ "Words named " { $snippet { $emphasis "operation" } "-tree" } " works on directory trees recursively, and also accepts regular files." }
|
{ "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:"
|
"Deleting directory trees recursively:"
|
||||||
{ $subsections delete-tree }
|
{ $subsections delete-tree }
|
||||||
"Copying directory trees recursively:"
|
"Copying directory trees recursively:"
|
||||||
|
|
|
@ -1,10 +1,24 @@
|
||||||
! Copyright (C) 2004, 2008 Slava Pestov, Doug Coleman.
|
! Copyright (C) 2004, 2008 Slava Pestov, Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel accessors sequences combinators fry io.directories
|
USING: accessors arrays kernel sequences combinators fry
|
||||||
io.pathnames io.files.info io.files.types io.files.links
|
io.directories io.pathnames io.files.info io.files.types
|
||||||
io.backend ;
|
io.files.links io.backend ;
|
||||||
IN: io.directories.hierarchy
|
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 -- )
|
: delete-tree ( path -- )
|
||||||
dup link-info directory? [
|
dup link-info directory? [
|
||||||
[ [ [ delete-tree ] each ] with-directory-files ]
|
[ [ [ delete-tree ] each ] with-directory-files ]
|
||||||
|
@ -28,4 +42,3 @@ DEFER: copy-tree-into
|
||||||
|
|
||||||
: copy-trees-into ( files to -- )
|
: copy-trees-into ( files to -- )
|
||||||
'[ _ copy-tree-into ] each ;
|
'[ _ copy-tree-into ] each ;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! (c)2010 Joe Groff bsd license
|
! (c)2010 Joe Groff bsd license
|
||||||
USING: arrays fry globs io.directories io.files.info
|
USING: arrays fry globs io.directories io.directories.hierarchy
|
||||||
io.pathnames kernel regexp sequences vocabs.loader
|
io.files.info io.pathnames kernel regexp sequences vocabs.loader
|
||||||
vocabs.metadata ;
|
vocabs.metadata ;
|
||||||
IN: vocabs.metadata.resources
|
IN: vocabs.metadata.resources
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue