2008-11-14 01:25:00 -05:00
|
|
|
! Copyright (C) 2008 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: accessors arrays combinators io io.files kernel
|
2008-12-08 00:51:13 -05:00
|
|
|
math.parser sequences system vocabs.loader calendar math
|
|
|
|
symbols fry prettyprint ;
|
2008-12-02 22:49:59 -05:00
|
|
|
IN: tools.files
|
2008-11-14 01:25:00 -05:00
|
|
|
|
2008-11-14 01:51:14 -05:00
|
|
|
<PRIVATE
|
|
|
|
|
2008-11-14 01:25:00 -05:00
|
|
|
: ls-time ( timestamp -- string )
|
|
|
|
[ hour>> ] [ minute>> ] bi
|
2008-12-08 00:51:13 -05:00
|
|
|
[ number>string 2 CHAR: 0 pad-left ] bi@ ":" glue ;
|
2008-11-14 01:25:00 -05:00
|
|
|
|
|
|
|
: ls-timestamp ( timestamp -- string )
|
|
|
|
[ month>> month-abbreviation ]
|
|
|
|
[ day>> number>string 2 CHAR: \s pad-left ]
|
|
|
|
[
|
|
|
|
dup year>> dup now year>> =
|
|
|
|
[ drop ls-time ] [ nip number>string ] if
|
|
|
|
5 CHAR: \s pad-left
|
|
|
|
] tri 3array " " join ;
|
|
|
|
|
|
|
|
: read>string ( ? -- string ) "r" "-" ? ; inline
|
|
|
|
|
|
|
|
: write>string ( ? -- string ) "w" "-" ? ; inline
|
|
|
|
|
2008-11-14 01:44:01 -05:00
|
|
|
: execute>string ( ? -- string ) "x" "-" ? ; inline
|
2008-11-14 01:25:00 -05:00
|
|
|
|
|
|
|
HOOK: (directory.) os ( path -- lines )
|
|
|
|
|
2008-11-14 01:51:14 -05:00
|
|
|
PRIVATE>
|
|
|
|
|
2008-11-14 01:25:00 -05:00
|
|
|
: directory. ( path -- )
|
|
|
|
[ (directory.) ] with-directory-files [ print ] each ;
|
|
|
|
|
2008-12-08 00:51:13 -05:00
|
|
|
SYMBOLS: device-name mount-point type
|
|
|
|
available-space free-space used-space total-space
|
|
|
|
percent-used percent-free ;
|
|
|
|
|
|
|
|
: percent ( real -- integer ) 100 * >integer ; inline
|
|
|
|
|
|
|
|
: file-system-spec ( file-system-info obj -- str )
|
|
|
|
{
|
|
|
|
{ device-name [ device-name>> ] }
|
|
|
|
{ mount-point [ mount-point>> ] }
|
|
|
|
{ type [ type>> ] }
|
2008-12-09 01:58:34 -05:00
|
|
|
{ available-space [ available-space>> [ 0 ] unless* ] }
|
|
|
|
{ free-space [ free-space>> [ 0 ] unless* ] }
|
|
|
|
{ used-space [ used-space>> [ 0 ] unless* ] }
|
|
|
|
{ total-space [ total-space>> [ 0 ] unless* ] }
|
2008-12-08 00:51:13 -05:00
|
|
|
{ percent-used [
|
2008-12-09 01:58:34 -05:00
|
|
|
[ used-space>> ] [ total-space>> ] bi
|
|
|
|
[ [ 0 ] unless* ] bi@ dup 0 =
|
2008-12-08 00:51:13 -05:00
|
|
|
[ 2drop 0 ] [ / percent ] if
|
|
|
|
] }
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
: file-systems-info ( spec -- seq )
|
|
|
|
file-systems swap '[ _ [ file-system-spec ] with map ] map ;
|
|
|
|
|
|
|
|
: file-systems. ( spec -- )
|
|
|
|
[ file-systems-info ]
|
|
|
|
[ [ unparse ] map ] bi prefix simple-table. ;
|
|
|
|
|
2008-11-14 01:25:00 -05:00
|
|
|
{
|
2008-12-02 22:49:59 -05:00
|
|
|
{ [ os unix? ] [ "tools.files.unix" ] }
|
|
|
|
{ [ os windows? ] [ "tools.files.windows" ] }
|
2008-11-14 01:25:00 -05:00
|
|
|
} cond require
|