1 USING: alien calendar io io-internals kernel libs-io math
2 namespaces prettyprint sequences windows-api ;
7 T{ winnt-shell } \ shell set-global
9 TUPLE: file name size mtime attributes ;
11 : ((directory*)) ( handle -- )
12 "WIN32_FIND_DATA" <c-object> [ FindNextFile ] 2keep
13 rot zero? [ 2drop ] [ , ((directory*)) ] if ;
15 : (directory*) ( path -- )
16 "WIN32_FIND_DATA" <c-object> [
17 FindFirstFile dup INVALID_HANDLE_VALUE = [
21 [ ((directory*)) ] keep FindClose win32-error=0/f ;
23 : append-star ( path -- path )
24 dup peek CHAR: \\ = "*" "\\*" ? append ;
26 M: winnt-shell directory* ( path -- seq )
27 normalize-pathname append-star [ (directory*) ] { } make ;
29 : WIN32_FIND_DATA>file-size ( WIN32_FILE_ATTRIBUTE_DATA -- n )
30 [ WIN32_FIND_DATA-nFileSizeLow ] keep
31 WIN32_FIND_DATA-nFileSizeHigh 32 shift + ;
33 M: winnt-shell make-file ( WIN32_FIND_DATA -- file )
34 [ WIN32_FIND_DATA-cFileName alien>u16-string ] keep
35 [ WIN32_FIND_DATA>file-size ] keep
37 WIN32_FIND_DATA-ftCreationTime
38 FILETIME>timestamp >local-time
40 WIN32_FIND_DATA-dwFileAttributes <file> ;
42 M: winnt-shell file. ( file -- )
43 [ [ file-attributes >oct write ] keep ] with-cell
45 [ [ file-size unparse write ] keep ] with-cell
47 [ [ file-mtime file-time-string write ] keep ] with-cell
49 [ file-name write ] with-cell ;
51 M: winnt-shell touch-file ( path -- )
52 #! Set the file write time to 'now'
54 dup maybe-create-file [ drop ] [ now set-file-write-time ] if ;