! Copyright (C) 2004, 2008 Slava Pestov, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays combinators combinators.short-circuit
-destructors fry io io.backend io.encodings.binary io.files
-io.files.types io.pathnames kernel namespaces sequences
-system vocabs vocabs.loader ;
+USING: accessors combinators combinators.short-circuit
+continuations destructors fry io io.backend io.encodings.binary
+io.files io.pathnames kernel namespaces sequences system vocabs ;
IN: io.directories
: set-current-directory ( path -- )
: with-directory ( path quot -- )
[ absolute-path current-directory ] dip with-variable ; inline
+: with-resource-directory ( quot -- )
+ [ "resource:" ] dip with-directory ; inline
+
! Creating directories
HOOK: make-directory io-backend ( path -- )
! Listing directories
TUPLE: directory-entry name type ;
-HOOK: >directory-entry os ( byte-array -- directory-entry )
+C: <directory-entry> directory-entry
HOOK: (directory-entries) os ( path -- seq )
: directory-entries ( path -- seq )
normalize-path
(directory-entries)
- [ name>> { "." ".." } member? not ] filter ;
+ [ name>> { "." ".." } member? ] reject ;
: directory-files ( path -- seq )
directory-entries [ name>> ] map! ;
HOOK: delete-directory io-backend ( path -- )
+: ?delete-file ( path -- )
+ '[ _ delete-file ] ignore-errors ;
+
: to-directory ( from to -- from to' )
over file-name append-path ;
to-directory move-file ;
: move-files-into ( files to -- )
- to-directory '[ _ move-file ] each ;
+ '[ _ move-file-into ] each ;
! Copying files
HOOK: copy-file io-backend ( from to -- )
to-directory copy-file ;
: copy-files-into ( files to -- )
- to-directory '[ _ copy-file ] each ;
+ '[ _ copy-file-into ] each ;
{
{ [ os unix? ] [ "io.directories.unix" require ] }