Stat file

Purpose: Get information about a file.

 stat-file <file> \
     size | type | path | name \
     to <variable>

stat-file obtains information about <file>, which is either the full path of a file or directory, or a name relative to the application home directory (see directories).

Clause "size" will store file's size in bytes to number <variable>, or it will be GG_ERR_FAILED (if operation failed, likely because file does not exist or you have no permissions to access it).

Clause "type" will store file's type to number <variable>, and it can be either GG_FILE (if it's a file) or GG_DIR (if it's a directory) or GG_ERR_FAILED (if operation failed, likely because file does not exist or you have no permissions to access it).

Clause "path" (in string <variable>) obtains the fully resolved path of the <file> (including symbolic links), and "name" is the name (a basename, without the path). If path cannot be resolved, then <variable> is an empty string.
Examples
To get file size in variable "sz", which is created here:
 stat-file "/home/user/file" size to sz

To determine if the object is a file or a directory:
 stat-file "/home/user/some_name" type to what
 if-true what equal GG_FILE
    @It's a file!
 else-if what equal GG_DIR
    @It's a directory!
 else-if
    @Doesn't exist!
 end-if

Get the fully resolved path of a file to string variable "fp", which is created here.
 stat-file "../file" path to fp

See also
Files
close-file  
copy-file  
delete-file  
file-position  
file-storage  
file-uploading  
lock-file  
open-file  
read-file  
read-line  
rename-file  
stat-file  
temporary-file  
uniq-file  
unlock-file  
write-file  
See all
documentation


Copyright (c) 2019-2024 Gliim LLC. All contents on this web site is "AS IS" without warranties or guarantees of any kind.