Skip to content

chmod ​

Changes the permissions of a file or directory. The mode parameter is a FileMode enum value. On non-Unix platforms, this returns Err with code ERR_FS_CHMOD_FAILED because POSIX permission bits are not supported there.

Signaturechmod(path: string, mode: FileMode): Result<void, FsError>

FileMode members ​

MemberValueOctal
Read2560o400
Write1280o200
Execute640o100
OwnerRead2560o400
OwnerWrite1280o200
OwnerExecute640o100
GroupRead320o040
GroupWrite160o020
GroupExecute80o010
OtherRead40o004
OtherWrite20o002
OtherExecute10o001
AllRead2920o444
AllWrite1460o222
AllExecute730o111
FullOwner4480o700
FullGroup560o070
FullOther70o007
Full5110o777

Example ​

tyrus
import { FsError, chmod, FileMode } from "tyrus:fs";

match (chmod("./file.txt", FileMode.AllRead)) {
    Ok(_) => { print("permissions updated"); } // permissions updated
    Err(error) => { printError(error.code); } // ERR_FS_CHMOD_FAILED
}
match (chmod("./file.txt", FileMode.FullOwner)) {
    Ok(_) => { print("permissions updated"); } // permissions updated
    Err(error) => { printError(error.code); } // ERR_FS_CHMOD_FAILED
}