FileAccess Tcl Reference Documentation

FileAccess

Current Version: 11.5.0

Chilkat.FileAccess

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

Load or save text and binary files, append data, replace file contents, and work with explicit character encodings when needed.

File management

Copy, rename, delete, compare, split, reassemble, and inspect files using straightforward file-system utility methods.

Directories and paths

Create, remove, check, and work with directories, and use path helpers to extract filenames, extensions, directory names, and related path parts.

Open-file operations

Open files for lower-level reading or writing, seek within files, read blocks, and process large files without loading everything at once.

Timestamps and metadata

Get or set file times, inspect sizes and existence, and use metadata helpers when coordinating file processing workflows.

Special file utilities

Generate temporary filenames, work with symbolic links, scan for byte fragments, and perform text replacement in files.

Common pattern: Use 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

# 'this' is not a keyword in Tcl. It can freely be used as a variable name.
set this [new CkFileAccess]

Properties

CurrentDir
string
# ckStr is a CkString
CkFileAccess_get_CurrentDir $this $ckStr
set strVal [CkFileAccess_get_currentDir $this]

Returns the current working directory of the calling process. Relative file and directory paths are resolved against this process-wide working directory.

Process-wide setting: The working directory belongs to the process, not to an individual FileAccess object. Changing it can therefore affect relative-path behavior elsewhere in the application.

top
DebugLogFilePath
string
# ckStr is a CkString
CkFileAccess_get_DebugLogFilePath $this $ckStr
set strVal [CkFileAccess_get_debugLogFilePath $this]
CkFileAccess_put_DebugLogFilePath $this $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.

More Information and Examples
top
EndOfFile
boolean 1/0
set boolVal [CkFileAccess_get_EndOfFile $this]

Returns 1 when the currently open file is positioned at end-of-file; otherwise returns 0.

Open-file state: This property applies to the file opened by OpenForRead, OpenForWrite, OpenForReadWrite, OpenForAppend, or FileOpen.

top
FileOpenError
integer
set intVal [CkFileAccess_get_FileOpenError $this]

Provides the detailed open-error code from the most recent call to FileOpen, OpenForRead, OpenForWrite, OpenForReadWrite, or OpenForAppend.

CodeMeaning
0Success; no open error.
1Access denied.
2File not found.
3General, non-specific open error.
4File already exists.
5The path refers to a directory and the requested access involves writing.
6Too many symbolic links were encountered while resolving the path.
7The process already has the maximum number of files open.
8The pathname is too long.
9The system-wide limit on open files has been reached.
10The pathname refers to a device special file for which no corresponding device exists.
11Insufficient kernel memory was available.
12A file was to be created, but the containing device has no space available.
13A pathname component expected to be a directory is not a directory.
14The regular file is too large to be opened because of an operating-system limitation.
15The path is on a read-only filesystem and write access was requested.
Use with FileOpenErrorMsg: FileOpenError is useful for programmatic handling; FileOpenErrorMsg provides the corresponding human-readable message.

top
FileOpenErrorMsg
string
# ckStr is a CkString
CkFileAccess_get_FileOpenErrorMsg $this $ckStr
set strVal [CkFileAccess_get_fileOpenErrorMsg $this]

Returns the human-readable message corresponding to FileOpenError for the most recent file-open attempt.

top
LastErrorHtml
string
# ckStr is a CkString
CkFileAccess_get_LastErrorHtml $this $ckStr
set strVal [CkFileAccess_get_lastErrorHtml $this]

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.

top
LastErrorText
string
# ckStr is a CkString
CkFileAccess_get_LastErrorText $this $ckStr
set strVal [CkFileAccess_get_lastErrorText $this]

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.

top
LastErrorXml
string
# ckStr is a CkString
CkFileAccess_get_LastErrorXml $this $ckStr
set strVal [CkFileAccess_get_lastErrorXml $this]

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.

top
LastMethodSuccess
boolean 1/0
set boolVal [CkFileAccess_get_LastMethodSuccess $this]
CkFileAccess_put_LastMethodSuccess $this $boolVal

Indicates the success or failure of the most recent method call: 1 means success, 0 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.

top
LockFileOnOpen
boolean 1/0
set boolVal [CkFileAccess_get_LockFileOnOpen $this]
CkFileAccess_put_LockFileOnOpen $this $boolVal
Introduced in version 9.5.0.80

Windows only. If 1, 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 0.

File sharing: Windows file sharing is established when the file handle is opened. Set this property before calling an OpenFor* method.

top
Utf8
boolean 1/0
set boolVal [CkFileAccess_get_Utf8 $this]
CkFileAccess_put_Utf8 $this $boolVal

When set to 1, all string arguments and return values are interpreted as UTF-8 strings. When set to 0, they are interpreted as ANSI strings.

In Chilkat v11.0.0 and later, the default value is 1. Before v11.0.0, it was 0.

top
VerboseLogging
boolean 1/0
set boolVal [CkFileAccess_get_VerboseLogging $this]
CkFileAccess_put_VerboseLogging $this $boolVal

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
string
# ckStr is a CkString
CkFileAccess_get_Version $this $ckStr
set strVal [CkFileAccess_get_version $this]

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

AppendAnsi
# text is a string
set status [CkFileAccess_AppendAnsi $this $text]

Appends text to the currently open file after converting the string to the legacy ANSI character encoding used by Chilkat for the platform.

Character encoding: Use AppendText or AppendSb when an explicit encoding such as utf-8 is preferred.

Returns 1 for success, 0 for failure.

top
AppendBd
# bd is a CkBinData
set status [CkFileAccess_AppendBd $this $bd]
Introduced in version 9.5.0.76

Appends all bytes contained in bd to the currently open file without text conversion.

Returns 1 for success, 0 for failure.

top
AppendSb
# sb is a CkStringBuilder
# charset is a string
set status [CkFileAccess_AppendSb $this $sb $charset]
Introduced in version 9.5.0.76

Appends the text contained in sb to the currently open file using the character encoding specified by charset.

Returns 1 for success, 0 for failure.

top
AppendText
# str is a string
# charset is a string
set status [CkFileAccess_AppendText $this $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 1 for success, 0 for failure.

top
AppendUnicodeBOM
set status [CkFileAccess_AppendUnicodeBOM $this]

Appends the UTF-16 little-endian byte-order mark to the currently open file. The two bytes written are FF FE.

BOM placement: A BOM normally belongs at the beginning of a text file. This method appends bytes at the current write position, so call it before writing text when creating a new UTF-16LE file.

Returns 1 for success, 0 for failure.

top
AppendUtf8BOM
set status [CkFileAccess_AppendUtf8BOM $this]

Appends the UTF-8 byte-order mark to the currently open file. The three bytes written are EF BB BF.

UTF-8 BOM: A UTF-8 BOM is optional. Some software uses it as an encoding signature, while other software expects BOM-less UTF-8.

Returns 1 for success, 0 for failure.

top
DirAutoCreate
# filePath is a string
set status [CkFileAccess_DirAutoCreate $this $filePath]

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.

Difference from DirEnsureExists: Use DirAutoCreate when you have a file path. Use DirEnsureExists when the argument itself is a directory path.

Returns 1 for success, 0 for failure.

top
DirCreate
# dirPath is a string
set status [CkFileAccess_DirCreate $this $dirPath]

Creates the directory specified by dirPath. Parent directories must already exist; use DirEnsureExists when missing parent directories should also be created.

Returns 1 for success, 0 for failure.

top
DirDelete
# dirPath is a string
set status [CkFileAccess_DirDelete $this $dirPath]

Deletes the directory specified by dirPath. The directory must be empty; use TreeDelete to recursively delete a directory and its contents.

Returns 1 for success, 0 for failure.

top
DirEnsureExists
# dirPath is a string
set status [CkFileAccess_DirEnsureExists $this $dirPath]

Ensures that the complete directory path dirPath exists, creating missing directories along the path as needed.

Returns 1 for success, 0 for failure.

top
DirExists
# dirPath is a string
set retBool [CkFileAccess_DirExists $this $dirPath]
Introduced in version 10.0.0

Returns 1 if dirPath exists as a directory; otherwise returns 0.

top
FileClose
CkFileAccess_FileClose $this

Closes the currently open file and releases its operating-system file handle. Any exclusive lock obtained through LockFileOnOpen is released at this time.

top
FileContentsEqual
# filePath1 is a string
# filePath2 is a string
set retBool [CkFileAccess_FileContentsEqual $this $filePath1 $filePath2]

Compares filePath1 and filePath2 byte-for-byte and returns 1 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.

Binary comparison: The comparison is byte-oriented. Text encodings, line-ending conventions, and Unicode normalization are not interpreted or normalized.
top
FileCopy
# existingFilepath is a string
# newFilepath is a string
# failIfExists is a boolean
set status [CkFileAccess_FileCopy $this $existingFilepath $newFilepath $failIfExists]

Copies existingFilepath to newFilepath. If failIfExists is 1 and the destination already exists, the copy fails instead of overwriting it.

Returns 1 for success, 0 for failure.

top
FileDelete
# filePath is a string
set status [CkFileAccess_FileDelete $this $filePath]

Deletes the file specified by filePath.

Returns 1 for success, 0 for failure.

top
FileExists
# filePath is a string
set retBool [CkFileAccess_FileExists $this $filePath]

Returns 1 if filePath exists; otherwise returns 0. Use FileExists3 when the application must distinguish "does not exist" from "could not determine because of an error."

top
FileExists3
# path is a string
set retInt [CkFileAccess_FileExists3 $this $path]
Introduced in version 9.5.0.45

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.

top
FileOpen
# filePath is a string
# accessMode is an integer
# shareMode is an integer
# createDisposition is an integer
# attributes is an integer
set status [CkFileAccess_FileOpen $this $filePath $accessMode $shareMode $createDisposition $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.

CategoryCommon values
AccessGENERIC_READ = 0x80000000, GENERIC_WRITE = 0x40000000
SharingFILE_SHARE_READ = 0x1, FILE_SHARE_WRITE = 0x2
DispositionCREATE_NEW=1, CREATE_ALWAYS=2, OPEN_EXISTING=3, OPEN_ALWAYS=4, TRUNCATE_EXISTING=5
Open failures: When this method fails, inspect FileOpenError and FileOpenErrorMsg for the reason.

Returns 1 for success, 0 for failure.

top
FileReadBd
# maxNumBytes is an integer
# binData is a CkBinData
set status [CkFileAccess_FileReadBd $this $maxNumBytes $binData]
Introduced in version 9.5.0.64

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.

Destination behavior: Existing bytes already present in binData are preserved; newly read bytes are appended.

Returns 1 for success, 0 for failure.

top
FileRename
# existingFilepath is a string
# newFilepath is a string
set status [CkFileAccess_FileRename $this $existingFilepath $newFilepath]

Renames or moves existingFilepath to newFilepath using the local filesystem.

Returns 1 for success, 0 for failure.

top
FileSeek
# offset is an integer
# origin is an integer
set status [CkFileAccess_FileSeek $this $offset $origin]

Moves the current file position by offset bytes relative to origin.

0Offset from the beginning of the file.
1Offset from the current file position.
2Offset from end-of-file; negative offsets are commonly used.
Random access: Seeking changes where the next read or write occurs; it does not itself read, write, or resize the file.

Returns 1 for success, 0 for failure.

top
FileSize
# filePath is a string
set status [CkFileAccess_FileSize $this $filePath]

Returns the file size in bytes as a signed 32-bit integer, or -1 on failure.

Large files: A signed 32-bit result cannot represent files larger than approximately 2 GB. Use FileSize64 or FileSizeStr for large files.

Returns 1 for success, 0 for failure.

top
FileSize64
# filePath is a string
set retInt64 [CkFileAccess_FileSize64 $this $filePath]
Introduced in version 9.5.0.88

Returns the size of filePath in bytes as a signed 64-bit integer, or -1 on failure.

top
FileSizeStr
# filePath is a string
# outStr is a CkString (output)
set status [CkFileAccess_FileSizeStr $this $filePath $outStr]
set retStr [CkFileAccess_fileSizeStr $this $filePath]
Introduced in version 9.5.0.80

Returns the size of filePath in bytes as a decimal string. This avoids the range limitation of a 32-bit integer return value.

Returns 1 for success, 0 for failure.

top
FileType
# path is a string
set retInt [CkFileAccess_FileType $this $path]
Introduced in version 9.5.0.77

Examines path and classifies the filesystem entry.

-1Unable to determine because of permissions or another error.
0Does not exist.
1Regular file.
2Directory.
3Symbolic link.
4Windows shortcut.
99Another filesystem type.
Future values: Additional file-type codes may be added in future versions as needed.
More Information and Examples
top
FileWriteBd
# binData is a CkBinData
# offset is an integer
# numBytes is an integer
set status [CkFileAccess_FileWriteBd $this $binData $offset $numBytes]
Introduced in version 9.5.0.64

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 1 for success, 0 for failure.

More Information and Examples
top
GenBlockId
# index is an integer
# length is an integer
# encoding is a string
# outStr is a CkString (output)
set status [CkFileAccess_GenBlockId $this $index $length $encoding $outStr]
set retStr [CkFileAccess_genBlockId $this $index $length $encoding]
Introduced in version 9.5.0.58

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.

Ordering: Fixed-width decimal identifiers preserve numeric ordering when identifiers are compared lexically, provided the chosen width is large enough for all indexes.

Returns 1 for success, 0 for failure.

top
GetDirectoryName
# path is a string
# outStr is a CkString (output)
set status [CkFileAccess_GetDirectoryName $this $path $outStr]
set retStr [CkFileAccess_getDirectoryName $this $path]
Introduced in version 9.5.0.64

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 1 for success, 0 for failure.

More Information and Examples
top
GetExtension
# path is a string
# outStr is a CkString (output)
set status [CkFileAccess_GetExtension $this $path $outStr]
set retStr [CkFileAccess_getExtension $this $path]
Introduced in version 9.5.0.64

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 1 for success, 0 for failure.

More Information and Examples
top
GetFileName
# path is a string
# outStr is a CkString (output)
set status [CkFileAccess_GetFileName $this $path $outStr]
set retStr [CkFileAccess_getFileName $this $path]
Introduced in version 9.5.0.64

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 1 for success, 0 for failure.

More Information and Examples
top
GetFileNameWithoutExtension
# path is a string
# outStr is a CkString (output)
set status [CkFileAccess_GetFileNameWithoutExtension $this $path $outStr]
set retStr [CkFileAccess_getFileNameWithoutExtension $this $path]
Introduced in version 9.5.0.64

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 1 for success, 0 for failure.

More Information and Examples
top
GetFileTimeStr
# path is a string
# which is an integer
# outStr is a CkString (output)
set status [CkFileAccess_GetFileTimeStr $this $path $which $outStr]
set retStr [CkFileAccess_getFileTimeStr $this $path $which]
Introduced in version 11.0.0

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.

Portability: Creation/birth time is not available on every filesystem. The documented Chilkat behavior on Linux is to return the last-modified time when creation time is unavailable.

Returns 1 for success, 0 for failure.

top
GetNumBlocks
# blockSize is an integer
set retInt [CkFileAccess_GetNumBlocks $this $blockSize]
Introduced in version 9.5.0.58

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.

Calculation: Conceptually this is ceil(fileSize / blockSize) for a non-empty file.
top
GetTempFilename
# dirPath is a string
# prefix is a string
# outStr is a CkString (output)
set status [CkFileAccess_GetTempFilename $this $dirPath $prefix $outStr]
set retStr [CkFileAccess_getTempFilename $this $dirPath $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 1 for success, 0 for failure.

top
OpenForAppend
# filePath is a string
set status [CkFileAccess_OpenForAppend $this $filePath]

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.

Open failures: If the open/create operation fails, inspect FileOpenError and FileOpenErrorMsg. On Windows, LockFileOnOpen can request exclusive access for this method.

Returns 1 for success, 0 for failure.

top
OpenForRead
# filePath is a string
set status [CkFileAccess_OpenForRead $this $filePath]

Opens an existing filePath for reading. The file may contain text or binary data and must already exist.

Open failures: If the open/create operation fails, inspect FileOpenError and FileOpenErrorMsg. On Windows, LockFileOnOpen can request exclusive access for this method.

Returns 1 for success, 0 for failure.

More Information and Examples
top
OpenForReadWrite
# filePath is a string
set status [CkFileAccess_OpenForReadWrite $this $filePath]

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.

Open failures: If the open/create operation fails, inspect FileOpenError and FileOpenErrorMsg. On Windows, LockFileOnOpen can request exclusive access for this method.

Returns 1 for success, 0 for failure.

top
OpenForWrite
# filePath is a string
set status [CkFileAccess_OpenForWrite $this $filePath]

Opens filePath for writing. The file is created if necessary; if it already exists, it is truncated to zero length when opened.

Open failures: If the open/create operation fails, inspect FileOpenError and FileOpenErrorMsg. On Windows, LockFileOnOpen can request exclusive access for this method.

Returns 1 for success, 0 for failure.

top
ReadBinaryToEncoded
# filePath is a string
# encoding is a string
# outStr is a CkString (output)
set status [CkFileAccess_ReadBinaryToEncoded $this $filePath $encoding $outStr]
set retStr [CkFileAccess_readBinaryToEncoded $this $filePath $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.

Encoding is not encryption: These encodings transform bytes into text; they do not provide confidentiality.

Returns 1 for success, 0 for failure.

More Information and Examples
top
ReadBlockBd
# blockIndex is an integer
# blockSize is an integer
# bd is a CkBinData
set retBool [CkFileAccess_ReadBlockBd $this $blockIndex $blockSize $bd]
Introduced in version 9.5.0.79

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.

Destination behavior: Existing contents of bd are preserved; the block bytes are appended.
top
ReadEntireTextFile
# filePath is a string
# charset is a string
# outStrFileContents is a CkString (output)
set status [CkFileAccess_ReadEntireTextFile $this $filePath $charset $outStr]
set retStr [CkFileAccess_readEntireTextFile $this $filePath $charset]

Reads the entire file at filePath, decodes its bytes using charset, and returns the resulting text.

Charset matters: The charset controls byte-to-character conversion. Use the encoding that actually represents the file; incorrect charset selection can produce incorrect text or conversion failure.

Returns 1 for success, 0 for failure.

top
ReadNextFragment
# startAtBeginning is a boolean
# beginMarker is a string
# endMarker is a string
# charset is a string
# sb is a CkStringBuilder
set retInt [CkFileAccess_ReadNextFragment $this $startAtBeginning $beginMarker $endMarker $charset $sb]
Introduced in version 9.5.0.80

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 1, scanning restarts at the beginning of the file; otherwise it continues after the previously matched fragment.

1A fragment was found and appended.
0No matching fragment was found.
-1An error occurred while reading.
More Information and Examples
top
ReassembleFile
# partsDirPath is a string
# partPrefix is a string
# partExtension is a string
# reassembledFilename is a string
set status [CkFileAccess_ReassembleFile $this $partsDirPath $partPrefix $partExtension $reassembledFilename]

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.

Byte-for-byte reconstruction: Reassembly is a binary operation; no text decoding or newline conversion is performed.

Returns 1 for success, 0 for failure.

More Information and Examples
top
ReplaceStrings
# filePath is a string
# charset is a string
# existingString is a string
# replacementString is a string
set retInt [CkFileAccess_ReplaceStrings $this $filePath $charset $existingString $replacementString]

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.

Text operation: This is character-based replacement after decoding the file. It is not suitable for arbitrary binary files.
top
SetCurrentDir
# dirPath is a string
set status [CkFileAccess_SetCurrentDir $this $dirPath]

Changes the current working directory of the calling process to dirPath.

Process-wide effect: The current directory is normally process-wide, so changing it can affect relative paths used by other code or threads. Absolute paths avoid that dependency.

Returns 1 for success, 0 for failure.

top
SetFileTimes
# filePath is a string
# createTime is a CkDateTime
# lastAccessTime is a CkDateTime
# lastModTime is a CkDateTime
set retBool [CkFileAccess_SetFileTimes $this $filePath $createTime $lastAccessTime $lastModTime]

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.

Filesystem differences: Timestamp availability and precision are filesystem- and operating-system-dependent.
top
SetLastModified
# filePath is a string
# lastModified is a CkDateTime
set retBool [CkFileAccess_SetLastModified $this $filePath $lastModified]

Sets the last-modified timestamp of filePath from lastModified. The precision actually stored depends on the underlying filesystem.

top
SplitFile
# fileToSplit is a string
# partPrefix is a string
# partExtension is a string
# partSize is an integer
# destDir is a string
set status [CkFileAccess_SplitFile $this $fileToSplit $partPrefix $partExtension $partSize $destDir]

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 1 for success, 0 for failure.

More Information and Examples
top
SymlinkCreate
# targetPath is a string
# linkPath is a string
set status [CkFileAccess_SymlinkCreate $this $targetPath $linkPath]
Introduced in version 9.5.0.77

Creates a symbolic link at linkPath that refers to targetPath.

Windows note: A Windows symbolic link is not the same as a Windows shortcut. Windows may require elevated privileges or an operating-system configuration such as Developer Mode that permits unprivileged symbolic-link creation, depending on system policy and how the application is launched.

Returns 1 for success, 0 for failure.

More Information and Examples
top
SymlinkTarget
# linkPath is a string
# outStr is a CkString (output)
set status [CkFileAccess_SymlinkTarget $this $linkPath $outStr]
set retStr [CkFileAccess_symlinkTarget $this $linkPath]
Introduced in version 9.5.0.77

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.

Link vs. target: A symbolic link is a filesystem object that refers to another path. A Windows shortcut is a separate shell-file format; Chilkat supports both here even though they are different mechanisms.

Returns 1 for success, 0 for failure.

top
TreeDelete
# path is a string
set status [CkFileAccess_TreeDelete $this $path]

Recursively deletes the directory tree rooted at path, including contained files and subdirectories.

Destructive operation: This operation is recursive and destructive. Ensure path identifies the intended tree before calling it.

Returns 1 for success, 0 for failure.

top
Truncate
set status [CkFileAccess_Truncate $this]
Introduced in version 9.5.0.80

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.

Use with FileSeek: A common pattern is to seek to the desired new length and then call Truncate.

Returns 1 for success, 0 for failure.

top
WriteEntireTextFile
# filePath is a string
# textData is a string
# charset is a string
# includedPreamble is a boolean
set status [CkFileAccess_WriteEntireTextFile $this $filePath $textData $charset $includedPreamble]

Creates or opens filePath, encodes textData using charset, writes the resulting bytes, and closes the file. Existing file content is replaced. If includePreamble is 1, an appropriate preamble/BOM is included for encodings such as UTF-8 or UTF-16.

BOM terminology: A BOM is part of the byte representation of the text file; it is not part of the application string itself.

Returns 1 for success, 0 for failure.

More Information and Examples
top

Deprecated

FileRead Deprecated
# maxNumBytes is an integer
# outBytes is a CkByteData (output)
set status [CkFileAccess_FileRead $this $maxNumBytes $outData]

Reads up to maxNumBytes bytes from the current file position and advances the file position by the number of bytes actually read. An empty byte array is returned on error.

End of file: A short read is normal near end-of-file. Use EndOfFile when the caller needs to distinguish EOF state explicitly.

Returns 1 for success, 0 for failure.

top
FileWrite Deprecated
# data is a CkByteData
set status [CkFileAccess_FileWrite $this $data]

Writes all bytes in data at the current file position and advances the position accordingly.

Returns 1 for success, 0 for failure.

top
GetFileTime
# returns a CkDateTime
# path is a string
# which is an integer
set ret_ckDateTime [CkFileAccess_GetFileTime $this $path $which]
Introduced in version 9.5.0.71
This method is deprecated and replaced by GetFileTimeStr

Deprecated. Use GetFileTimeStr instead.

Returns one file timestamp as a CkDateTime, selected by which: 0 = last-modified, 1 = last-access, 2 = creation.

Portability: Creation/birth time is not available on every filesystem. The historical Chilkat behavior documented for Linux is to return the last-modified time when creation time is unavailable.

Returns NULL on failure

top
GetLastModified
# returns a CkDateTime
# path is a string
set ret_ckDateTime [CkFileAccess_GetLastModified $this $path]
Introduced in version 9.5.0.66
This method is deprecated and replaced by GetFileTimeStr

Deprecated. Use GetFileTimeStr instead.

Returns the last-modified date/time for path as a CkDateTime. The documented resolution of this legacy method is one second.

Returns NULL on failure

top
ReadBlock Deprecated
# blockIndex is an integer
# blockSize is an integer
# outBytes is a CkByteData (output)
set status [CkFileAccess_ReadBlock $this $blockIndex $blockSize $outData]
Introduced in version 9.5.0.58

Reads the zero-based block blockIndex from the currently open file, where each block is blockSize bytes. If the final block is shorter than blockSize, only the remaining bytes are returned.

Returns 1 for success, 0 for failure.

top
ReadEntireFile Deprecated
# filePath is a string
# outBytes is a CkByteData (output)
set status [CkFileAccess_ReadEntireFile $this $filePath $outData]

Reads the entire file at filePath as raw bytes and returns the binary data.

Memory use: The whole file is loaded into memory. For very large files, use OpenForRead together with FileReadBd or block-oriented methods.

Returns 1 for success, 0 for failure.

top
WriteEntireFile Deprecated
# filePath is a string
# fileData is a CkByteData
set status [CkFileAccess_WriteEntireFile $this $filePath $fileData]

Creates or opens filePath, writes all bytes from fileData, and closes the file. Existing file content is replaced.

Returns 1 for success, 0 for failure.

top