filemode

filemode(file)

Equivalent to stat(file).mode

Examples

  1. Get the file mode of a file:

    julia> filemode("path/to/file.txt")
    0o644

    This example returns the file mode of the file located at "path/to/file.txt". The file mode is represented in octal format.

  2. Use filemode within a conditional statement:

    julia> if filemode("path/to/file.txt") & 0o400 != 0
              println("Read permission granted.")
          else
              println("Read permission denied.")
          end

    Here, the file mode is checked to determine if the file has read permission. If the read permission bit is set, it prints "Read permission granted." Otherwise, it prints "Read permission denied."

  3. Check file mode for execution permission:
    julia> isexecutable(filemode("path/to/script.jl"))
    true

    This example checks whether the file "path/to/script.jl" has execution permission. The isexecutable function returns true if the execution permission bit is set in the file mode.

Common mistake example:

julia> filemode("nonexistent/file.txt")
ERROR: SystemError: stat: no such file or directory (ENOENT)

In this example, the file specified does not exist, resulting in a SystemError. Make sure to provide a valid file path as an argument to the filemode function.

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
Details

Checking you are not a robot: