factor/library/io/files.factor

43 lines
1.1 KiB
Factor
Raw Normal View History

! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: io
2005-09-27 14:12:17 -04:00
USING: hashtables kernel lists math namespaces sequences strings
styles ;
! Words for accessing filesystem meta-data.
2004-11-25 21:51:47 -05:00
2005-06-19 18:31:02 -04:00
: path+ ( path path -- path ) "/" swap append3 ;
2005-09-01 16:37:32 -04:00
: exists? ( file -- ? ) stat >boolean ;
2005-09-01 16:37:32 -04:00
2005-03-19 00:30:49 -05:00
: directory? ( file -- ? ) stat car ;
2005-09-01 16:37:32 -04:00
: directory ( dir -- list )
2006-01-09 01:34:23 -05:00
(directory)
[ { "." ".." } member? not ] subset natural-sort ;
2005-09-01 16:37:32 -04:00
: file-length ( file -- length ) stat third ;
2005-09-01 16:37:32 -04:00
2005-09-14 00:37:50 -04:00
: resource-path ( path -- path )
"resource-path" get [ "." ] unless* swap path+ ;
: <resource-stream> ( path -- stream )
#! Open a file path relative to the Factor source code root.
2005-09-14 00:37:50 -04:00
resource-path <file-reader> ;
2005-09-27 14:12:17 -04:00
: (file.) ( name path -- )
file associate [ format* ] with-style ;
2005-09-27 14:12:17 -04:00
DEFER: directory.
: (directory.) ( name path -- )
dup [ directory. ] curry
[ "/" append (file.) ] write-outliner ;
2005-09-27 14:12:17 -04:00
: file. ( dir name -- )
tuck path+
dup directory? [ (directory.) ] [ (file.) terpri ] if ;
2005-09-27 14:12:17 -04:00
: directory. ( dir -- )
dup directory [ file. ] each-with ;