JanetDocsSourcePlaygroundTutorialsI'm Feeling luckyCommunityGitHub sign in

os/stat

core-api


    cfunction
    src/core/os.c on line 2553, column 1

    (os/stat path &opt tab-or-kwd)

    Gets information about a file or directory. Returns a table unless 
    the second argument `tab-or-kwd` is a keyword, in which case it 
    returns only that field/value from `stat()`. If `tab-or-kwd` is a 
    table, reuses it as basis of the returned table. If the file or 
    directory does not exist, returns nil. The keys are:

    * `:dev` - device that the file is on
    * `:mode` - type of file, one of `:file`, `:directory`, `:block`, 
      `:character`, `:fifo`, `:socket`, `:link`, or `:other`
    * `:int-permissions` - a Unix permission integer like 8r744
    * `:permissions` - a Unix permission string like "rwxr--r--"
    * `:uid` - file uid
    * `:gid` - file gid
    * `:nlink` - number of links to file
    * `:rdev` - real device of file. 0 on Windows
    * `:size` - size of file in bytes
    * `:blocks` - number of blocks in file. 0 on Windows
    * `:blocksize` - size of blocks in file. 0 on Windows
    * `:accessed` - timestamp when file last accessed
    * `:changed` - timestamp when file last changed (permissions 
      changed)
    * `:modified` - timestamp when file last modified (content changed)


3 examplesSign in to add an example
Loading...
(defn recent-mods
  "List the files in the current directory which have changed within the last hour."
  []
  (filter
    (fn [fname]
      (<
        (- (os/time) 3600)
        (os/stat fname :modified)))
    (os/dir ".")))
cellularmitosisPlayground
(defn ls-sockets
  "List the sockets in the current directory."
  []
  (filter
    (fn [fname] (= :socket (os/stat fname :mode)))
    (os/dir ".")))
cellularmitosisPlayground
(os/shell "touch foo")
(os/stat "foo" :modified)  # => 1593836002
(os/touch "foo")
(os/stat "foo" :modified)  # => 1593836013
cellularmitosisPlayground