Hi guys, I have a question. Is there any way to get the octal value (mode) of a file in crystal ?
Do you mean like the permissions of a file, or like if you have file = File.new "/some/file.txt", "rw" to know that file has a mode of rw?
I mean the permissions, like for example 0755
Can access it off of File::Info, so like File.info("./LICENSE").permissions.value.to_s(8). This would give you the octal value representing the permissions as a String. Without the to_s(8), it would be the same value but in base 10.
Thanks a lot ! I tried before your post to use Crystal::System::File.stat, but unfortunately it is not documented
Right, that’s an internal API so it’s not expected to be documented or used directly.
1 Like