FileAccess Lua Reference Documentation
chilkat.FileAccess
Current Version: 11.7.0
Markdown version of this page for AI tools (v 11.7.0) · all AI docs
Chilkat.FileAccess
Load or save text and binary files, append data, replace file contents,
and work with explicit character encodings when needed.
Copy, rename, delete, compare, split, reassemble, and inspect files using
straightforward file-system utility methods.
Create, remove, check, and work with directories, and use path helpers to
extract filenames, extensions, directory names, and related path parts.
Open files for lower-level reading or writing, seek within files, read
blocks, and process large files without loading everything at once.
Get or set file times, inspect sizes and existence, and use metadata
helpers when coordinating file processing workflows.
Generate temporary filenames, work with symbolic links, scan for byte
fragments, and perform text replacement in files.
For an extended overview, see
FileAccess Class Overview.
Read, write, compare, copy, split, inspect, and manage files and paths.
Chilkat.FileAccess provides general-purpose file-system
utilities for applications that need direct control over files, directories,
paths, timestamps, and low-level file operations. It can read, write, append,
seek, compare, copy, rename, delete, split, reassemble, and inspect files,
and also includes helpers for directory operations, path parsing, symbolic
links, temporary filenames, block-based reading, fragment scanning, text
replacement, and open-file access.
Read and write files
File management
Directories and paths
Open-file operations
Timestamps and metadata
Special file utilities
FileAccess for local file-system tasks that are outside the
scope of a specific protocol class. It is especially useful for preparing
files before upload, saving downloaded data, comparing or splitting files,
reading large files in blocks, manipulating paths, or performing small
filesystem operations without using platform-specific APIs.
Object Creation
local chilkat = require("chilkat")
local file_access = chilkat.FileAccess.new()Creates the object (chilkat.FileAccess() does the same). Lua's garbage collector frees it when it is no longer referenced; file_access:dispose() frees it at once, and in Lua 5.4 and later local file_access <close> = chilkat.FileAccess.new() frees it when the block ends. Calling a method of a disposed object raises an error.
Errors
A method that fails returns nil followed by the error text, as io.open does: local body, err = file_access:method(...), where err is the object's last_error_text. Wrap the call in assert() to raise an error with that text instead. Methods that answer a question return true or false, numbers are returned as they are (check last_method_success where the description says a value means failure), and property reads and writes never fail for Chilkat reasons.
Misuse raises a Lua error: a wrong argument type or a missing argument (bad argument #1 to ...), an unknown property name, a write to a read-only property, an out-of-range integer, or an object of the wrong class.
Names are Chilkat's in snake_case: QuickGetStr is quick_get_str, LastErrorText is last_error_text. Properties are fields (file_access.verbose_logging = true) and methods use the colon (file_access:method(...)). Strings are UTF-8; binary data is a Lua string of bytes. Indexes are 0-based, as in every Chilkat API. Unlocking: call chilkat.unlock_bundle("...") once at startup.
Properties
CurrentDir
local strVal = file_access.current_dir
Returns the current working directory of the calling process. Relative file and directory paths are resolved against this process-wide working directory.
FileAccess object. Changing it can therefore affect relative-path behavior elsewhere in the application.DebugLogFilePath
local strVal = file_access.debug_log_file_path
file_access.debug_log_file_path = strVal
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
EndOfFile
local boolVal = file_access.end_of_file
Returns true when the currently open file is positioned at end-of-file; otherwise returns false.
OpenForRead, OpenForWrite, OpenForReadWrite, OpenForAppend, or FileOpen.FileOpenError
local intVal = file_access.file_open_error
Provides the detailed open-error code from the most recent call to FileOpen, OpenForRead, OpenForWrite, OpenForReadWrite, or OpenForAppend.
| Code | Meaning |
|---|---|
0 | Success; no open error. |
1 | Access denied. |
2 | File not found. |
3 | General, non-specific open error. |
4 | File already exists. |
5 | The path refers to a directory and the requested access involves writing. |
6 | Too many symbolic links were encountered while resolving the path. |
7 | The process already has the maximum number of files open. |
8 | The pathname is too long. |
9 | The system-wide limit on open files has been reached. |
10 | The pathname refers to a device special file for which no corresponding device exists. |
11 | Insufficient kernel memory was available. |
12 | A file was to be created, but the containing device has no space available. |
13 | A pathname component expected to be a directory is not a directory. |
14 | The regular file is too large to be opened because of an operating-system limitation. |
15 | The path is on a read-only filesystem and write access was requested. |
FileOpenError is useful for programmatic handling; FileOpenErrorMsg provides the corresponding human-readable message.FileOpenErrorMsg
local strVal = file_access.file_open_error_msg
Returns the human-readable message corresponding to FileOpenError for the most recent file-open attempt.
LastErrorHtml
local strVal = file_access.last_error_html
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
local strVal = file_access.last_error_text
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
local strVal = file_access.last_error_xml
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
local boolVal = file_access.last_method_success
file_access.last_method_success = boolVal
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
LockFileOnOpen
local boolVal = file_access.lock_file_on_open
file_access.lock_file_on_open = boolVal
Windows only. If true, OpenForAppend, OpenForRead, OpenForReadWrite, and OpenForWrite request exclusive access to the file. Other processes are prevented from opening the file until FileClose releases the handle. The default is false.
OpenFor* method.VerboseLogging
local boolVal = file_access.verbose_logging
file_access.verbose_logging = boolVal
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
local strVal = file_access.version
Methods
AppendAnsi
-- ok is true, or nil and err on failure
local ok, err = file_access:append_ansi(text)
Appends text to the currently open file after converting the string to the legacy ANSI character encoding used by Chilkat for the platform.
AppendText or AppendSb when an explicit encoding such as utf-8 is preferred.Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
AppendBd
-- ok is true, or nil and err on failure
local ok, err = file_access:append_bd(bd)
Appends all bytes contained in bd to the currently open file without text conversion.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
AppendSb
-- charset is a string
-- ok is true, or nil and err on failure
local ok, err = file_access:append_sb(sb, charset)
Appends the text contained in sb to the currently open file using the character encoding specified by charset.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
AppendText
-- charset is a string
-- ok is true, or nil and err on failure
local ok, err = file_access:append_text(str, charset)
Appends str to the currently open file after encoding the text with the character set named by charset, such as utf-8 or iso-8859-1.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
AppendUnicodeBOM
local ok, err = file_access:append_unicode_bom()
Appends the UTF-16 little-endian byte-order mark to the currently open file. The two bytes written are FF FE.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
AppendUtf8BOM
local ok, err = file_access:append_utf8_bom()
Appends the UTF-8 byte-order mark to the currently open file. The three bytes written are EF BB BF.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
DirAutoCreate
-- ok is true, or nil and err on failure
local ok, err = file_access:dir_auto_create(file_path)
Ensures that the directory portion of filePath exists. Any missing parent directories are created; the final path component is treated as a filename and is not created as a directory.
DirAutoCreate when you have a file path. Use DirEnsureExists when the argument itself is a directory path.Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
DirCreate
-- ok is true, or nil and err on failure
local ok, err = file_access:dir_create(dir_path)
Creates the directory specified by dirPath. Parent directories must already exist; use DirEnsureExists when missing parent directories should also be created.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
DirDelete
-- ok is true, or nil and err on failure
local ok, err = file_access:dir_delete(dir_path)
Deletes the directory specified by dirPath. The directory must be empty; use TreeDelete to recursively delete a directory and its contents.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
DirEnsureExists
-- ok is true, or nil and err on failure
local ok, err = file_access:dir_ensure_exists(dir_path)
Ensures that the complete directory path dirPath exists, creating missing directories along the path as needed.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
DirExists
-- flag is true or false
local flag = file_access:dir_exists(dir_path)
Returns true if dirPath exists as a directory; otherwise returns false.
Returns true or false: an answer, not a success flag.
FileClose
Closes the currently open file and releases its operating-system file handle. Any exclusive lock obtained through LockFileOnOpen is released at this time.
FileContentsEqual
-- file_path2 is a string
-- flag is true or false
local flag = file_access:file_contents_equal(file_path1, file_path2)
Compares filePath1 and filePath2 byte-for-byte and returns true only when their contents are identical. File sizes are compared first; when sizes match, the files are compared incrementally rather than being loaded entirely into memory.
Returns true or false: an answer, not a success flag.
FileCopy
-- new_filepath is a string
-- fail_if_exists is a boolean
-- ok is true, or nil and err on failure
local ok, err = file_access:file_copy(existing_filepath, new_filepath, fail_if_exists)
Copies existingFilepath to newFilepath. If failIfExists is true and the destination already exists, the copy fails instead of overwriting it.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
FileDelete
-- ok is true, or nil and err on failure
local ok, err = file_access:file_delete(file_path)
Deletes the file specified by filePath.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
FileExists
-- flag is true or false
local flag = file_access:file_exists(file_path)
Returns true if filePath exists; otherwise returns false. Use FileExists3 when the application must distinguish "does not exist" from "could not determine because of an error."
Returns true or false: an answer, not a success flag.
FileExists3
-- n is an integer
local n = file_access:file_exists3(path)
Checks whether path exists and returns a three-state result: 1 if it exists, 0 if it does not exist, and -1 if Chilkat could not determine the result because of permissions or another filesystem error.
FileOpen
-- access_mode is an integer
-- share_mode is an integer
-- create_disposition is an integer
-- attributes is an integer
-- ok is true, or nil and err on failure
local ok, err = file_access:file_open(file_path, access_mode, share_mode, create_disposition, attributes)
Windows-specific low-level open. Opens filePath using arguments modeled after the Win32 CreateFile API. For portable code, prefer OpenForRead, OpenForWrite, OpenForReadWrite, or OpenForAppend.
| Category | Common values |
|---|---|
| Access | GENERIC_READ = 0x80000000, GENERIC_WRITE = 0x40000000 |
| Sharing | FILE_SHARE_READ = 0x1, FILE_SHARE_WRITE = 0x2 |
| Disposition | CREATE_NEW=1, CREATE_ALWAYS=2, OPEN_EXISTING=3, OPEN_ALWAYS=4, TRUNCATE_EXISTING=5 |
FileOpenError and FileOpenErrorMsg for the reason.Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
FileReadBd
-- bin_data is a chilkat.BinData
-- ok is true, or nil and err on failure
local ok, err = file_access:file_read_bd(max_num_bytes, bin_data)
Reads up to maxNumBytes bytes from the current file position and appends the bytes to binData. The file position advances by the number of bytes read.
binData are preserved; newly read bytes are appended.Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
FileRename
-- new_filepath is a string
-- ok is true, or nil and err on failure
local ok, err = file_access:file_rename(existing_filepath, new_filepath)
Renames or moves existingFilepath to newFilepath using the local filesystem.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
FileSeek
-- origin is an integer
-- ok is true, or nil and err on failure
local ok, err = file_access:file_seek(offset, origin)
Moves the current file position by offset bytes relative to origin.
0 | Offset from the beginning of the file. |
1 | Offset from the current file position. |
2 | Offset from end-of-file; negative offsets are commonly used. |
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
FileSize
-- n is an integer
local n = file_access:file_size(file_path)
Returns the file size in bytes as a signed 32-bit integer.
0, which is the same as for an empty file. To detect failure, use FileSizeStr, which fails instead of returning a size, or check first with FileExists3.FileSize64 or FileSizeStr for large files.FileSize64
-- n is an integer
local n = file_access:file_size64(file_path)
Returns the size of filePath in bytes as a signed 64-bit integer.
0, which is the same as for an empty file. To detect failure, use FileSizeStr, which fails instead of returning a size, or check first with FileExists3.FileSizeStr
-- str is a string, or nil and err on failure
local str, err = file_access:file_size_str(file_path)
Returns the size of filePath in bytes as a decimal string. This avoids the range limitation of a 32-bit integer return value.
Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
FileType
-- n is an integer
local n = file_access:file_type(path)
Examines path and classifies the filesystem entry.
-1 | Unable to determine because of permissions or another error. |
0 | Does not exist. |
1 | Regular file. |
2 | Directory. |
3 | Symbolic link. |
4 | Windows shortcut. |
99 | Another filesystem type. |
FileWrite2
-- ok is true, or nil and err on failure
local ok, err = file_access:file_write2(byte_data)
Writes exactly szByteData bytes beginning at pByteData to the currently open file at the current file position.
szByteData bytes.Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
FileWriteBd
-- offset is an integer
-- num_bytes is an integer
-- ok is true, or nil and err on failure
local ok, err = file_access:file_write_bd(bin_data, offset, num_bytes)
Writes bytes from binData to the currently open file. offset selects the starting byte within the BinData; numBytes selects how many bytes to write. Set both to 0 to write the entire BinData, or set numBytes to 0 to write all remaining bytes beginning at offset.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
GenBlockId
-- length is an integer
-- encoding is a string
-- str is a string, or nil and err on failure
local str, err = file_access:gen_block_id(index, length, encoding)
Generates a fixed-width decimal block identifier from index, padded to length characters, and then encodes those bytes using encoding (for example base64, hex, or ascii). This utility was originally added for block-oriented uploads such as Azure Blob block uploads.
Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
GetDirectoryName
-- str is a string, or nil and err on failure
local str, err = file_access:get_directory_name(path)
Returns the directory portion of path according to Chilkat path-parsing rules.
GetDirectoryName('C:\MyDir\MySubDir\myfile.ext') -> 'C:\MyDir\MySubDir\'
GetDirectoryName('C:\MyDir\MySubDir') -> 'C:\MyDir\'
GetDirectoryName('C:\') -> 'C:\'Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
GetExtension
-- str is a string, or nil and err on failure
local str, err = file_access:get_extension(path)
Returns the filename extension portion of path, including the leading period. A period appearing only in a directory name is not treated as the file extension.
GetExtension('C:\mydir.old\myfile.ext') -> '.ext'
GetExtension('C:\mydir.old\') -> ''Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
GetFileName
-- str is a string, or nil and err on failure
local str, err = file_access:get_file_name(path)
Returns the final filename component of path, including its extension. If the path ends with a directory separator, the returned filename is empty.
GetFileName('C:\mydir\myfile.ext') -> 'myfile.ext'
GetFileName('C:\mydir\') -> ''Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
GetFileNameWithoutExtension
-- str is a string, or nil and err on failure
local str, err = file_access:get_file_name_without_extension(path)
Returns the final filename component of path with its extension removed. If path ends with a directory separator, the returned value is empty.
GetFileNameWithoutExtension('C:\mydir\myfile.ext') -> 'myfile'
GetFileNameWithoutExtension('C:\mydir\') -> ''Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
GetFileTimeStr
-- which is an integer
-- str is a string, or nil and err on failure
local str, err = file_access:get_file_time_str(path, which)
Returns one file timestamp as an ISO 8601 UTC string in the form YYYY-MM-DDTHH:MM:SSZ. The which argument selects 0 = last-modified, 1 = last-access, or 2 = creation.
Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
GetNumBlocks
-- n is an integer
local n = file_access:get_num_blocks(block_size)
Returns how many blockSize-byte blocks are required to cover the currently open file. A partial final block counts as one block. Returns 0 for an empty file and -1 if no file is open.
ceil(fileSize / blockSize) for a non-empty file.GetTempFilename
-- prefix is a string
-- str is a string, or nil and err on failure
local str, err = file_access:get_temp_filename(dir_path, prefix)
Generates a temporary pathname in dirPath using prefix and a random alphanumeric suffix, in the general form prefix_xxxx.TMP. The returned pathname is guaranteed not to already exist at the time it is generated.
Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
OpenForAppend
-- ok is true, or nil and err on failure
local ok, err = file_access:open_for_append(file_path)
Opens filePath for writing at end-of-file. The file is created if it does not exist. Existing content is preserved, and the initial file position is at the end.
FileOpenError and FileOpenErrorMsg. On Windows, LockFileOnOpen can request exclusive access for this method.Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
OpenForRead
-- ok is true, or nil and err on failure
local ok, err = file_access:open_for_read(file_path)
Opens an existing filePath for reading. The file may contain text or binary data and must already exist.
FileOpenError and FileOpenErrorMsg. On Windows, LockFileOnOpen can request exclusive access for this method.Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
OpenForReadWrite
-- ok is true, or nil and err on failure
local ok, err = file_access:open_for_read_write(file_path)
Opens filePath for both reading and writing. The file is created if necessary. Existing content is preserved, and the initial file position is at the beginning.
FileOpenError and FileOpenErrorMsg. On Windows, LockFileOnOpen can request exclusive access for this method.Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
OpenForWrite
-- ok is true, or nil and err on failure
local ok, err = file_access:open_for_write(file_path)
Opens filePath for writing. The file is created if necessary; if it already exists, it is truncated to zero length when opened.
FileOpenError and FileOpenErrorMsg. On Windows, LockFileOnOpen can request exclusive access for this method.Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
ReadBinaryToEncoded
-- encoding is a string
-- str is a string, or nil and err on failure
local str, err = file_access:read_binary_to_encoded(file_path, encoding)
Reads the entire file at filePath as binary data and returns an encoded textual representation. Supported encoding names documented for this method include base64, hex, qp, and url.
Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
ReadBlockBd
-- block_size is an integer
-- bd is a chilkat.BinData
-- ok is true, or nil and err on failure
local ok, err = file_access:read_block_bd(block_index, block_size, bd)
Reads the zero-based block blockIndex from the currently open file, using blockSize bytes per block, and appends the bytes to bd. A partial final block is appended at its actual length.
bd are preserved; the block bytes are appended.Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
ReadEntireTextFile
-- charset is a string
-- str is a string, or nil and err on failure
local str, err = file_access:read_entire_text_file(file_path, charset)
Reads the entire file at filePath, decodes its bytes using charset, and returns the resulting text.
Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
ReadNextFragment
-- begin_marker is a string
-- end_marker is a string
-- charset is a string
-- sb is a chilkat.StringBuilder
-- n is an integer
local n = file_access:read_next_fragment(start_at_beginning, begin_marker, end_marker, charset, sb)
Scans the currently open file for the next text fragment beginning with beginMarker and ending with endMarker. The matched fragment, including both markers, is decoded using charset and appended to sb. If startAtBeginning is true, scanning restarts at the beginning of the file; otherwise it continues after the previously matched fragment.
1 | A fragment was found and appended. |
0 | No matching fragment was found. |
-1 | An error occurred while reading. |
ReassembleFile
-- part_prefix is a string
-- part_extension is a string
-- reassembled_filename is a string
-- ok is true, or nil and err on failure
local ok, err = file_access:reassemble_file(parts_dir_path, part_prefix, part_extension, reassembled_filename)
Reassembles a file previously divided by SplitFile. Parts are read from partsDirPath using the supplied partPrefix and partExtension, and the combined bytes are written to reassembledFilename.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
ReplaceStrings
-- charset is a string
-- existing_string is a string
-- replacement_string is a string
-- n is an integer
local n = file_access:replace_strings(file_path, charset, existing_string, replacement_string)
Reads the file at filePath as text using charset, replaces occurrences of existingString with replacementString, writes the updated text back to the file, and returns the number of replacements made.
SetCurrentDir
-- ok is true, or nil and err on failure
local ok, err = file_access:set_current_dir(dir_path)
Changes the current working directory of the calling process to dirPath.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
SetFileTimes
-- create_time is a chilkat.DateTime
-- last_access_time is a chilkat.DateTime
-- last_mod_time is a chilkat.DateTime
-- ok is true, or nil and err on failure
local ok, err = file_access:set_file_times(file_path, create_time, last_access_time, last_mod_time)
Sets the creation, last-access, and last-modified timestamps for filePath from the supplied CkDateTime objects. On filesystems that do not support a creation/birth time, createTime is ignored.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
SetLastModified
-- last_modified is a chilkat.DateTime
-- ok is true, or nil and err on failure
local ok, err = file_access:set_last_modified(file_path, last_modified)
Sets the last-modified timestamp of filePath from lastModified. The precision actually stored depends on the underlying filesystem.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
SplitFile
-- part_prefix is a string
-- part_extension is a string
-- part_size is an integer
-- dest_dir is a string
-- ok is true, or nil and err on failure
local ok, err = file_access:split_file(file_to_split, part_prefix, part_extension, part_size, dest_dir)
Splits fileToSplit into sequential binary parts of up to partSize bytes and writes them to destDir using partPrefix and partExtension. Use ReassembleFile to reconstruct the original file.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
SymlinkCreate
-- link_path is a string
-- ok is true, or nil and err on failure
local ok, err = file_access:symlink_create(target_path, link_path)
Creates a symbolic link at linkPath that refers to targetPath.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
SymlinkTarget
-- str is a string, or nil and err on failure
local str, err = file_access:symlink_target(link_path)
Returns the resolved target pathname for the symbolic link at linkPath. On Windows, this method also understands Windows shortcut (.lnk) files and returns the absolute target path.
Returns the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
TreeDelete
-- ok is true, or nil and err on failure
local ok, err = file_access:tree_delete(path)
Recursively deletes the directory tree rooted at path, including contained files and subdirectories.
path identifies the intended tree before calling it.Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
Truncate
local ok, err = file_access:truncate()
Truncates the currently open file at the current file position. Bytes at and after that position are removed, making the current position the new end-of-file.
Truncate.Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
WriteEntireTextFile
-- text_data is a string
-- charset is a string
-- included_preamble is a boolean
-- ok is true, or nil and err on failure
local ok, err = file_access:write_entire_text_file(file_path, text_data, charset, included_preamble)
Creates or opens filePath, encodes textData using charset, writes the resulting bytes, and closes the file. Existing file content is replaced. If includePreamble is true, an appropriate preamble/BOM is included for encodings such as UTF-8 or UTF-16.
Returns true on success, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.