Struct

struct FileDescriptor

public struct FileDescriptor

Description: Obtains the file handle information.

Note:

A file handle is a data structure allocated by an operating system to trace a file, and is used to identify an instance for opening the file. A file handle contains the metadata (such as the file name, path, size, and modification time) of a file and the physical location of the file data on the disk. The file handle format may vary according to the operating system. In Unix and Linux, the file handle is usually a non-negative integer, which is allocated by the operating system kernel and returned to the application when the file is opened. In Windows, the file handle is usually a pointer to a file object. It is allocated by the operating system kernel and returned to the application when the file is opened. A file handle, regardless of its format, can be used by applications to read, write, and modify files.

prop fileHandle

public prop fileHandle: CPointer<Unit>

Description: Obtains the file handle information in Windows.

Type: CPointer<Unit>

prop fileHandle

public prop fileHandle: Int32

Description: Obtains the file handle information in Linux.

Type: Int32

struct FileInfo

public struct FileInfo <: Equatable<FileInfo> {
    public init(path: Path)
    public init(path: String)
}

Description: Obtains the file metadata in a file system.

Note:

File metadata refers to file-related information in a file system, including the name, size, creation time, modification time, access time, and owner of as well as permissions on a file.

The underlying implementation of FileInfo does not support direct file attribute cache. Each API calling FileInfo obtains the latest file attribute.

Note that when the file attribute is obtained twice by using the same FileInfo instance, if the file entity is modified or replaced by another user or process, the file attribute obtained later may not be the expected one. For the same FileInfo instance, the corresponding file entity may be modified or replaced by another user or process during the interval between two adjacent operations of obtaining the file attribute of the instance, so that the file attribute obtained later may not be the expected one. To avoid this problem, you can set file permissions or lock key file operations.

Parent Type:

prop creationTime

public prop creationTime: DateTime

Description: Obtains the creation time.

Type: DateTime

Throws:

  • FSException: If an error occurs in the system interface called at the underlying layer, this exception is thrown.

prop lastAccessTime

public prop lastAccessTime: DateTime

Description: Obtains the last access time.

Type: DateTime

Throws:

  • FSException: If an error occurs in the system interface called at the underlying layer, this exception is thrown.

prop lastModificationTime

public prop lastModificationTime: DateTime

Description: Obtains the last modification time.

Type: DateTime

Throws:

  • FSException: If an error occurs in the system interface called at the underlying layer, this exception is thrown.

prop length

public prop length: Int64

Description: Returns the current file size.

  • For a file, the value indicates the disk space occupied by a single file.
  • For a directory, it indicates the disk space occupied by all files in the directory.

Type: Int64

Throws:

  • FSException: If an error occurs in the system interface called at the underlying layer, this exception is thrown.

prop parentDirectory

public prop parentDirectory: Option<FileInfo>

Description: Obtains the metadata of the parent directory and returns the metadata in Option<FileInfo> format. If there is a parent directory, Option<FileInfo>.Some(v) is returned. Otherwise, Option<FileInfo>.None is returned.

Type: Option<FileInfo>

prop path

public prop path: Path

Description: Obtains the file path and returns it in Path format.

Type: Path

prop symbolicLinkTarget

public prop symbolicLinkTarget: Option<Path>

Description: Obtains the target path of a link and returns the path in Option<Path> format. For a symbolic link, Option<Path>.Some(v) is returned. Otherwise, Option<Path>.None is returned.

Type: Option<Path>

init(Path)

public init(path: Path)

Description: Creates a FileInfo instance.

Parameters:

  • path: Path: directory path in the Path format

Throws:

  • FSException: If the path is invalid, this exception is thrown.

init(String)

public init(path: String)

Description: Creates a FileInfo instance.

Parameters:

Throws:

  • FSException: If the path is invalid, this exception is thrown.

func canExecute()

public func canExecute(): Bool

Description: Checks whether a user has the permission to execute the file corresponding to the instance.

  • For a file, checks whether a user has the permission to execute the file.
  • For a directory, checks whether a user has the permission to access the directory.
  • In Windows, the file name extension determines a user's permission to execute files. The user always has the permission to execute a directory. No operation is performed and true is returned.
  • In Linux and macOS, this function works normally.

Returns:

  • Bool: If the user has the permission. true is returned. If the user has no permission, false is returned.

Throws:

  • FSException: If an error occurs in the system interface called at the underlying layer, this exception is thrown.

func canRead()

public func canRead(): Bool

Description: Checks whether a user has the permission to read the file corresponding to the instance.

  • For a file, checks whether a user has the permission to read the file.
  • For a directory, checks whether a user has the permission to browse the directory.
  • In Windows, a user always has the read permission on the file and directory. No operation is performed and true is returned.
  • In Linux and macOS, this function works normally.

Returns:

  • Bool: If the user has the permission. true is returned. If the user has no permission, false is returned.

Throws:

  • FSException: If an error occurs in the system interface called at the underlying layer, this exception is thrown.

func canWrite()

public func canWrite(): Bool

Description: Checks whether a user has the permission to write the file corresponding to the instance.

  • For a file, checks whether a user has the permission to write the file.
  • For a directory, checks whether a user has the permission to delete, move, and create files in a directory.
  • In Windows, a user can write files normally and always has the write permission on the directory. No operation is performed and true is returned.
  • In Linux and macOS, this function works normally.

Returns:

  • Bool: If the user has the permission. true is returned. If the user has no permission, false is returned.

Throws:

  • FSException: If an error occurs in the system interface called at the underlying layer, this exception is thrown.

func isDirectory()

public func isDirectory(): Bool

Description: Checks whether a file is a directory.

Returns:

  • Bool: true: yes, false: no

Throws:

  • FSException: If an error occurs in the system interface called at the underlying layer, this exception is thrown.

func isFile()

public func isFile(): Bool

Description: Checks whether a file is a common file.

Returns:

  • Bool: true: yes, false: no

Throws:

  • FSException: If an error occurs in the system interface called at the underlying layer, this exception is thrown.

func isHidden()

public func isHidden(): Bool

Description: Checks whether a file is hidden.

Returns:

  • Bool: true: yes, false: no

func isReadOnly()

public func isReadOnly(): Bool

Description: Checks whether a file is read-only.

  • In Windows, the read-only permission on a file is effective and a user always has the permission to delete or modify the directory. No operation is performed and false is returned.
  • In Linux and macOS, this function works normally.

Returns:

  • Bool: true: yes, false: no

Throws:

  • FSException: If an error occurs in the system interface called at the underlying layer, this exception is thrown.
public func isSymbolicLink(): Bool

Description: Checks whether a file is a soft link.

Returns:

  • Bool: If the file is a soft link, true is returned; if the file is not a soft link, false is returned.

Throws:

  • FSException: If an error occurs in the system interface called at the underlying layer, this exception is thrown.

func setExecutable(Bool)

public func setExecutable(executable: Bool): Bool

Description: Sets whether the permission to execute a file corresponding to the current instance is granted for a user. If the user does not have the permission to modify the system permissions, an exception is thrown.

  • For a file, whether the permission to execute the file is granted for a user. For a directory, whether the permission to access the directory is granted for a user.
  • In Windows, the file name extension determines a user's permission to execute the file, and the user always has the permission to execute a directory. No operation is performed and false is returned.
  • In Linux and macOS, this function works normally. If the file entity corresponding to FileInfo is modified by other users or processes when this function is called, other modifications may not take effect due to the race condition.

Parameters:

  • executable: Bool: whether the user can execute the file

Returns:

  • Bool: If the operation is successful, true is returned. If the operation fails, false is returned.

func setReadable(Bool)

public func setReadable(readable: Bool): Bool

Description: Sets whether the read permission on a file corresponding to the current instance is granted for a user. If the user does not have the permission to modify the system permissions, an exception is thrown.

  • For a file, sets whether a user has the permission to read the file.
  • For a directory, sets whether a user has the permission to browse the directory.
  • In Windows, a user always has the read permission on files and directories and such read permission cannot be modified. No operation is performed. If readable is set to true, true is returned. If readable is set to false, false is returned.
  • In Linux and macOS, this function works normally. If the file entity corresponding to FileInfo is modified by other users or processes when this function is called, other modifications may not take effect due to the race condition.

Parameters:

  • readable: Bool: whether a user can read the file

Returns:

  • Bool: If the operation is successful, true is returned. If the operation fails, false is returned.

func setWritable(Bool)

public func setWritable(writable: Bool): Bool

Description: Sets whether the write permission on a file corresponding to the current instance is granted for a user. If the user does not have the permission to modify the system permissions, an exception is thrown.

  • For a file, sets whether a user has the permission to write the file.
  • For a directory, sets whether a user has the permission to delete, move, and create files in a directory.
  • In Windows, a user can write files normally and always has the write permission on directories and such write permission cannot be modified. No operation is performed and false is returned.
  • In Linux and macOS, this function works normally. If the file entity corresponding to FileInfo is modified by other users or processes when this function is called, other modifications may not take effect due to the race condition.

Parameters:

  • writable: Bool: whether a user can write the file

Returns:

  • Bool: If the operation is successful, true is returned. If the operation fails, false is returned.

operator func !=(FileInfo)

public operator func !=(that: FileInfo): Bool

Description: Checks whether the current FileInfo and the other FileInfo correspond to different files.

Parameters:

Returns:

  • Bool: true: yes, false: no

operator func ==(FileInfo)

public operator func ==(that: FileInfo): Bool

Description: Checks whether the current FileInfo and the other FileInfo correspond to the same file.

Parameters:

Returns:

  • Bool: true: yes, false: no

struct Path

public struct Path <: Equatable<Path> & Hashable & ToString {
    public init(rawPath: String)
}

Description: Provides path-related functions.

Path indicates the local path. (Windows supports the DOS device path and UNC path. The length limit is the same as that set in system settings.) The path string can contain a maximum of 4096 bytes (including the terminator\0).

Note:

An invalid path is one of the following:

  • A path containing invalid characters, such as spaces, tabs, and newline characters
  • A path containing invalid characters, such as special characters and control characters
  • A path containing a directory or file that does not exist
  • A path containing a directory or file that cannot be accessed. For example, the permission is insufficient or the directory or file is locked.

Enter a valid path without invalid characters so that the target file or directory can be accessed correctly.

Parent Type:

prop directoryName

public prop directoryName: Option<Path>

Description: Obtains the directory portion of Path and returns the result in Option<Path> format.

  • For the path "/a/b/c", Some (Path ("/a/b")) is returned.
  • For the path "/a/b/", Some(Path("/a/b")) is returned.
  • For the path "/a", Some(Path("/")) is returned.
  • For the path "/", Some(Path("/")) is returned.
  • For the path "./a/b", Some(Path("./a")) is returned.
  • For the path "./", Some(Path(".")) is returned.
  • For the path ".", None is returned.
  • For the path ".gitignore", None is returned.
  • For the path "a.txt", None is returned.
  • For the path "C:\a\b\c", Some(Path("C:\a\b")) is returned.
  • For the path "C:\a\b", Some(Path("C:\a\b")) is returned.

Returns: directory portion of the path input during construction. If the path input during construction does not contain any directory portion, None is returned.

Type: Option<Path>

Throws:

prop extensionName

public prop extensionName: Option<String>

Description: Obtains the file name extension of Path and returns the result in the Option<String> format.

  • For the path "./NewFile.txt", Some("txt") is returned.
  • For the path "./.gitignore", Some("gitignore") is returned.
  • For the path "./noextension", None is returned.
  • For the path "./a.b.c", Some("c") is returned.
  • For the path "./NewDir/", None is returned.
  • For the path "./NewDir/NewFile.", None is returned.

Returns: file name extension in the path input during construction. If the path input during construction does not contain the file name extension, None is returned.

Type: Option<String>

Throws:

prop fileName

public prop fileName: Option<String>

Description: Obtains the file name (including the file name extension) of Path and returns the result in the Option<String> format.

  • For the path "./NewFile.txt", Some("NewFile.txt") is returned.
  • For the path "./.gitignore", Some(".gitignore") is returned.
  • For the path "./noextension", Some("noextension") is returned.
  • For the path "./a.b.c", Some("a.b.c") is returned.
  • For the path "./NewDir/", None is returned.

Returns: file name (including the file name extension) in the path input during construction. If the path input during construction does not contain the file name (including the file name extension), None is returned.

Type: Option<String>

Throws:

prop fileNameWithoutExtension

public prop fileNameWithoutExtension: Option<String>

Description: Obtains the file name (excluding the file name extension) of Path and returns the result in the Option<String> format.

  • For the path "./NewFile.txt", Some("NewFile") is returned.
  • For the path "./.gitignore", None is returned.
  • For the path "./noextension", Some("noextension") is returned.
  • For the path "./a.b.c", Some("a.b") is returned.
  • For the path "./NewDir/", None is returned.

Returns: file name (excluding the file name extension) in the path input during construction. If the path input during construction does not contain the file name (excluding the file name extension), None is returned.

Type: Option<String>

Throws:

init(String)

public init(rawPath: String)

Description: When a Path instance is created, the validity of the path (including the absolute and relative path) string is not checked.

Parameters:

  • rawPath: String: string of the path

func hashCode()

public func hashCode(): Int64

Description: Obtains the hash value of Path.

Returns:

func isAbsolute()

public func isAbsolute(): Bool

Description: Checks whether Path is an absolute path. In Unix, the path starting with / is an absolute path.

Returns:

  • Bool: true: yes, false: no

Throws:

func isDirectory()

public func isDirectory(): Bool

Description: Checks whether Path is a directory. This function is mutually exclusive with isFile and isSymbolicLink.

Returns:

  • Bool: true: yes, false: no

Throws:

  • FSException: If the path does not exist or an error occurs in the system interface called at the underlying layer, this exception is thrown.
  • IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.

func isFile()

public func isFile(): Bool

Description: Checks whether Path is a file. This function is mutually exclusive with isSymbolicLink and isDirectory.

Returns:

  • Bool: true: yes, false: no

Throws:

  • FSException: If the path does not exist or an error occurs in the system interface called at the underlying layer, this exception is thrown.
  • IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.

func isRelative()

public func isRelative(): Bool

Description: Checks whether Path is a relative path. The result is opposite to that of the isAbsolute function.

Returns:

  • Bool: true: yes, false: no

Throws:

public func isSymbolicLink(): Bool

Description: Checks whether Path is a soft link. This function is mutually exclusive with isFile and isDirectory.

Returns:

  • Bool: true: yes, false: no

Throws:

  • FSException: If the path does not exist or an error occurs in the system interface called at the underlying layer, this exception is thrown.
  • IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.

func join(Path)

public func join(path: Path): Path

Description: Concatenates another path string after the current path to form a new path.

  • If "c" is concatenated after "a/b", "a/b/c" is returned.
  • If "b/c" is concatenated after "a", "a/b/c" is returned.

Returns:

Throws:

  • FSException: If path is an absolute path, this exception is thrown.
  • IllegalArgumentException: If the current path is empty or the current path or input parameter path is invalid, this exception is thrown.

func join(String)

public func join(path: String): Path

Description: Concatenates another path string after the current path to form a new path.

  • If "c" is concatenated after "a/b", "a/b/c" is returned.
  • If "b/c" is concatenated after "a", "a/b/c" is returned.

Returns:

Throws:

  • FSException: If path is an absolute path, this exception is thrown.
  • IllegalArgumentException: If the current path is empty or the current path or input parameter path is invalid, this exception is thrown.

func split()

public func split(): (Option<Path>, Option<String>)

Description: Splits Path into a directory and a file name and returns the splitting result (directoryName, fileName) in tuple format.

Returns:

  • (Option<Path>, Option<String>): tuple value. The first element indicates the path. If the path is obtained successfully, Option<Path>.Some(p) is returned. If the path fails to be obtained, Option<Path>.None is returned. The second element indicates the file name. If the file name is obtained successfully, Option<String>.Some(s) is returned. If the file name fails to be obtained, Option<String>.None is returned.

Throws:

func toCanonical()

public func toCanonical(): Path

Description: Normalizes Path and returns a normalized path in absolute path format.

All intermediate references and soft links are removed (soft links in the UNC path cannot be removed). For example, for the path "/foo/test/../test/bar.txt", "/foo/test/bar.txt" is returned after normalization.

Returns:

  • Path: Path instance of the normalized path

Throws:

  • FSException: If the path does not exist or cannot be normalized, this exception is thrown.
  • IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.

func toString()

public func toString(): String

Description: Obtains the path string of Path.

Returns:

operator func !=(Path)

public operator func !=(that: Path): Bool

Description: Checks whether two Path instances are different.

Parameters:

Returns:

  • Bool: true: yes, false: no

operator func ==(Path)

public operator func ==(that: Path): Bool

Description: Checks whether two Path instances are the same.

Parameters:

Returns:

  • Bool: true: yes, false: no