2006-05-15 00:03:55 -04:00
|
|
|
! Copyright (C) 2004, 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2005-06-19 17:50:35 -04:00
|
|
|
IN: io
|
2006-05-15 01:01:47 -04:00
|
|
|
USING: hashtables kernel math memory namespaces sequences
|
2006-03-27 22:20:42 -05:00
|
|
|
strings styles ;
|
2004-08-28 16:43:43 -04:00
|
|
|
|
2005-03-18 21:41:13 -05:00
|
|
|
! Words for accessing filesystem meta-data.
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: path+ ( str1 str2 -- str )
|
2006-02-06 14:31:54 -05:00
|
|
|
over "/" tail? [ append ] [ "/" swap append3 ] if ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: exists? ( path -- ? ) stat >boolean ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: directory? ( path -- ? ) stat first ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: directory ( path -- seq )
|
2006-01-09 01:34:23 -05:00
|
|
|
(directory)
|
|
|
|
[ { "." ".." } member? not ] subset natural-sort ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: file-length ( path -- n ) stat third ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2006-09-06 18:48:46 -04:00
|
|
|
: file-modified ( path -- n ) stat fourth ;
|
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: parent-dir ( path -- parent )
|
2006-03-27 22:20:42 -05:00
|
|
|
CHAR: / over last-index CHAR: \\ pick last-index max
|
2006-07-29 20:36:25 -04:00
|
|
|
dup -1 = [ 2drop "." ] [ head ] if ;
|
2006-03-27 22:20:42 -05:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: resource-path ( resource -- path )
|
2006-08-11 16:55:43 -04:00
|
|
|
\ resource-path get [ image parent-dir ] unless*
|
|
|
|
swap path+ ;
|
2005-06-19 18:53:58 -04:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: <resource-reader> ( resource -- stream )
|
2005-09-14 00:37:50 -04:00
|
|
|
resource-path <file-reader> ;
|
2005-09-27 14:12:17 -04:00
|
|
|
|
2006-06-14 02:16:53 -04:00
|
|
|
TUPLE: pathname string ;
|
2006-06-14 01:47:28 -04:00
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: (file.) ( name path -- )
|
2006-06-14 02:16:53 -04:00
|
|
|
<pathname> write-object ;
|
2005-12-19 02:12:40 -05:00
|
|
|
|
2005-09-27 14:12:17 -04:00
|
|
|
DEFER: directory.
|
|
|
|
|
2005-12-19 02:12:40 -05:00
|
|
|
: (directory.) ( name path -- )
|
2006-06-14 02:16:53 -04:00
|
|
|
>r "/" append r> dup <pathname> swap [ directory. ] curry
|
2006-06-14 01:47:28 -04:00
|
|
|
write-outliner terpri ;
|
2005-09-27 14:12:17 -04:00
|
|
|
|
|
|
|
: file. ( dir name -- )
|
2005-12-19 02:12:40 -05:00
|
|
|
tuck path+
|
|
|
|
dup directory? [ (directory.) ] [ (file.) terpri ] if ;
|
2005-09-27 14:12:17 -04:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: directory. ( path -- )
|
2005-12-19 02:12:40 -05:00
|
|
|
dup directory [ file. ] each-with ;
|