File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -186,3 +186,28 @@ If this function is acting as a *getter*, it will return the current working dir
186186local cwd = io.currentdir() -- Get cwd
187187io.currentdir("abc/abc") -- Set a new cwd
188188```
189+
190+ ---
191+ ### ` io.chmod `
192+ Get or set file permissions on Unix-like systems.
193+ #### Parameters
194+ 1 . A string path or file stream. If this parameter is absent, this function works as an * availability check* .
195+ 2 . The desired mode/permissions. If this parameter is absent, this function works as a * getter* .
196+ #### Returns
197+ If this function is acting as an * availability check* , it will return a boolean.
198+
199+ If this function is acting as a * getter* , it will return an integer if used on a supporting platform and there wasn't an error ` stat ` ing the file.
200+
201+ ``` pluto
202+ io.contents("chmod-test.txt", "") -- create chmod-test.txt with no contents
203+ if mode := io.chmod("chmod-test.txt") then
204+ print("File mode: %o":format(mode))
205+ mode |= 0o111 -- +x
206+ io.chmod("chmod-test.txt", mode)
207+ print("New file mode: %o":format(mode))
208+ elseif io.chmod() then
209+ print("Failed to stat chmod-test.txt")
210+ else
211+ print("chmod is not available on this platform.")
212+ end
213+ ```
You can’t perform that action at this time.
0 commit comments