2019-10-18 09:05:08 -04:00
|
|
|
! Copyright (C) 2004, 2007 Slava Pestov.
|
2006-05-15 00:03:55 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2005-06-19 17:50:35 -04:00
|
|
|
IN: io
|
2019-10-18 09:05:08 -04:00
|
|
|
USING: io-internals hashtables kernel math memory namespaces
|
|
|
|
|
sequences strings styles arrays definitions ;
|
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 )
|
2019-10-18 09:05:08 -04:00
|
|
|
>r dup "/" tail? [ 1 head* ] when r>
|
|
|
|
|
dup "/" head? [ 1 tail ] when
|
|
|
|
|
>r "/" r> 3append ;
|
|
|
|
|
|
|
|
|
|
: stat ( path -- directory? permissions length modified )
|
|
|
|
|
(stat) ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2006-10-31 00:52:02 -05:00
|
|
|
: exists? ( path -- ? ) stat >r 3drop r> >boolean ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2006-10-31 00:52:02 -05:00
|
|
|
: directory? ( path -- ? ) stat 3drop ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: directory ( path -- seq )
|
2019-10-18 09:05:08 -04:00
|
|
|
directory-fixup (directory)
|
2019-10-18 09:05:04 -04:00
|
|
|
[ { "." ".." } member? not ] subset ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2006-10-31 00:52:02 -05:00
|
|
|
: file-length ( path -- n ) stat 4array third ;
|
2005-09-01 16:37:32 -04:00
|
|
|
|
2006-10-31 00:52:02 -05:00
|
|
|
: file-modified ( path -- n ) stat >r 3drop r> ;
|
2006-09-06 18:48:46 -04:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: parent-dir ( path -- parent )
|
2019-10-18 09:05:08 -04:00
|
|
|
dup [ "/\\" member? ] find-last
|
|
|
|
|
drop dup [ head ] [ 2drop "." ] if ;
|
2006-03-27 22:20:42 -05:00
|
|
|
|
2019-10-18 09:05:04 -04:00
|
|
|
: resource-path ( path -- newpath )
|
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
|
|
|
|
2019-10-18 09:05:04 -04:00
|
|
|
: ?resource-path ( path -- newpath )
|
2006-09-29 23:03:27 -04:00
|
|
|
"resource:" ?head [ resource-path ] when ;
|
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
|
|
|
|
2019-10-18 09:05:08 -04:00
|
|
|
M: pathname where pathname-string 1 2array ;
|
|
|
|
|
|
|
|
|
|
M: pathname <=> [ pathname-string ] 2apply <=> ;
|
2006-09-29 20:45:24 -04:00
|
|
|
|
|
|
|
|
: home ( -- dir )
|
2019-10-18 09:05:08 -04:00
|
|
|
{
|
|
|
|
|
{ [ winnt? ] [ "USERPROFILE" os-env ] }
|
|
|
|
|
{ [ wince? ] [ image parent-dir ] }
|
|
|
|
|
{ [ unix? ] [ "HOME" os-env ] }
|
|
|
|
|
} cond ;
|