..  stat(file)

Returns a structure whose fields contain information about the file. The fields of the structure are:

========= ======================================================================
 size      The size (in bytes) of the file
 device    ID of the device that contains the file
 inode     The inode number of the file
 mode      The protection mode of the file
 nlink     The number of hard links to the file
 uid       The user id of the owner of the file
 gid       The group id of the file owner
 rdev      If this file refers to a device, the ID of the device it refers to
 blksize   The file-system preferred block size for the file
 blocks    The number of such blocks allocated
 mtime     Unix timestamp of when the file was last modified
 ctime     Unix timestamp of when the file was created
========= ======================================================================


The stat function in Julia is used to obtain information about a file. It returns a structure with fields containing various details about the file. Here are some examples of how to use the stat function:

Get file information:

julia> file_info = stat("path/to/file.txt")

This example obtains the file information for the file located at "path/to/file.txt" and stores it in the file_info variable.

Access specific fields:

julia> file_size = file_info.size
julia> file_mode = file_info.mode

These examples demonstrate how to access specific fields of the file_info structure. In the first line, it retrieves the file size, and in the second line, it retrieves the file mode.

Print all fields:

julia> for field in fieldnames(file_info)
           println("$field: ", getfield(file_info, field))

This example loops through all the fields of the file_info structure and prints their names and corresponding values.

Please note that the stat function is not a built-in Julia function, but it can be achieved using the Base.Stat module.

See Also

abspath, basename, chmod, countlines, cp, ctime, dirname, download, evalfile, expanduser, fdio, filemode, filesize, functionloc, gperm, homedir, include_string, isabspath, isblockdev, ischardev, isdir, isdirpath, isexecutable, isfifo, isfile, islink, ismount, ispath, isreadable, issetgid, issetuid, issticky, iswritable, joinpath, less, lstat, mkdir, mkpath, mktemp, mktempdir, mtime, mv, normpath, operm, poll_fd, poll_file, readall, readcsv, readdir, readdlm, readlines, readlink, realpath, relpath, rm, splitdir, splitdrive, splitext, stat, symlink, tempdir, tempname, touch, truncate, uperm, watch_file, writecsv,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: