File Operations (file)

file

File I/O, line operations, filesystem management, hash, zip/unzip.

33 functions Lua 5.3
file.file.append
file.append(path, content)
Append string to file. Creates file if not exists.
file.file.appends
file.appends(path, content)
Append content to file. Alias: file.append().
file.file.attrs
file.attrs(path)
Get detailed file attributes (POSIX stat). Returns mode, uid, gid, size, nlink, ino, timestamps, permissions string, typ…
file.file.chdir
file.chdir(path)
Change working directory.
file.file.copy
file.copy(src, dst)
Copy file.
file.file.currentdir
file.currentdir()
Get current working directory.
file.file.exists
file.exists(path)
Check if file/directory exists.
file.file.find
file.find(dir [, pattern [, maxdepth]])
Find files matching pattern.
file.file.get_line
file.get_line(path, n)
Get specific line from file.
file.file.get_lines
file.get_lines(path)
Get all lines as array. Empty file returns {''}.
file.file.info
file.info(path)
Get file information.
file.file.insert_line
file.insert_line(path, line_number, content)
Insert line before position. 0=append to end.
file.file.insert_lines
file.insert_lines(path, line_number, lines)
Insert multiple lines before position.
file.file.lattrs
file.lattrs(path)
Get file attributes using lstat (does NOT follow symlinks). Can detect symlinks (type='link').
file.file.line_count
file.line_count(path)
Count lines in file. Empty file returns 1 (XXTouch parity).
file.file.link
file.link(src, dst)
Create hard link.
file.file.list
file.list(dir)
List files in directory.
file.file.md5
file.md5(path)
Calculate file MD5 hash.
file.file.mkdir
file.mkdir(path)
Create directory recursively. Alias: file.mkdir_p().
file.file.move
file.move(src, dst)
Move/rename file.
file.file.read
file.read(path)
Read entire file content as string. Uses NSData.dataWithContentsOfFile:.
file.file.reads
file.reads(path)
Read file contents. Alias: file.read().
file.file.remove
file.remove(path)
Delete file or directory.
file.file.remove_line
file.remove_line(path, line_number)
Remove line at position. Returns the removed line content.
file.file.set_line
file.set_line(path, line_number, content)
Replace specific line. 0=append to end. Pads with empty lines if beyond file length.
file.file.set_lines
file.set_lines(path, lines)
Replace entire file content with array of lines.
file.file.sha1
file.sha1(path)
Calculate SHA-1 hash of file.
file.file.size
file.size(path)
Get file size in bytes.
file.file.touch
file.touch(path [, atime, mtime])
Create file if not exists, or update timestamps.
file.file.unzip
file.unzip(zip [, dest])
Extract ZIP archive.
file.file.write
file.write(path, content)
Write string to file (overwrites). Creates parent dirs if needed.
file.file.writes
file.writes(path, content)
Write content to file (overwrites). Alias: file.write().
file.file.zip
file.zip(output, path1, ...)
Create ZIP archive.