     to-directory copy-tree ;
 
 : copy-trees-into ( files to -- )
-    '[ _ copy-tree-into ] each ;
+    to-directory '[ _ copy-tree ] each ;

! See http://factorcode.org/license.txt for BSD license.
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

        bi
    ] [ delete-file ] if ;

DEFER: copy-trees-into

: copy-tree ( from to -- )
    normalize-path
    over link-info type>>
    {
        { +symbolic-link+ [ copy-link ] }
        { +directory+ [ '[ _ copy-trees-into ] with-directory-files ] }
        [ drop copy-file ]
    } case ;

