factor/library/io/files.factor

24 lines
754 B
Factor
Raw Normal View History

! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: io
USING: kernel lists namespaces sequences strings ;
! 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 ;
: exists? ( file -- ? ) stat >boolean ;
2005-03-19 00:30:49 -05:00
: directory? ( file -- ? ) stat car ;
: directory ( dir -- list ) (directory) [ lexi ] sort ;
: file-length ( file -- length ) stat third ;
: file-extension ( filename -- extension )
"." split cdr dup [ peek ] when ;
DEFER: <file-reader>
: resource-path ( -- path )
"resource-path" get [ "." ] unless* ;
: <resource-stream> ( path -- stream )
#! Open a file path relative to the Factor source code root.
resource-path swap path+ <file-reader> ;