Functions
func canonicalize(Path)
public func canonicalize(path: Path): Path
Description: Normalizes a path instance and obtains the normalized path in the form of an absolute path.
All intermediate references and soft links are processed (soft links in the UNC path cannot be normalized). For example, for the path /foo/test/../test/bar.txt, the function returns /foo/test/bar.txt.
Parameters:
Returns:
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 canonicalize(String)
public func canonicalize(path: String): Path
Description: Constructs a path instance using the path string, normalizes the instance, and obtains the normalized path in the form of an absolute path.
All intermediate references and soft links are processed (soft links in the UNC path cannot be normalized). For example, for the path /foo/test/../test/bar.txt, the function returns /foo/test/bar.txt.
Parameters:
- path: String: path string to be normalized
Returns:
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 copy(Path, Path, Bool)
public func copy(sourcePath: Path, to!: Path, overwrite!: Bool = false): Unit
Description: Implements the copy functionality of the file system for replication of files or directories.
When the target location exists and overwrite is true, this function requires that the type of sourcePath be the same as that of to. For example, if the type of sourcePath is Directory, the type of to must also be Directory. Otherwise, the function throws the FSException exception. Currently, the file types of Directory, Regular file, and SymbolicLink are supported.
Parameters:
- sourcePath: Path: address of the file to be copied
- to!: Path: target address
- overwrite!: Bool: whether to overwrite the target address. The default value is
false.
Throws:
- FSException: If the source file type is different from the target file type, this exception is thrown. If
overwriteisfalseand the target address exists, this exception is thrown. - IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.
func copy(String, String, Bool)
public func copy(sourcePath: String, to!: String, overwrite!: Bool = false): Unit
Description: Implements the copy functionality of the file system for replication of files or directories.
When the target location exists and overwrite is true, this function requires that the type of sourcePath be the same as that of to. For example, if the type of sourcePath is Directory, the type of to must also be Directory. Otherwise, the function throws the FSException exception. Currently, the file types of Directory, Regular file, and SymbolicLink are supported.
Parameters:
- sourcePath: String: address of the file to be copied
- to!: String: target address
- overwrite!: Bool: whether to overwrite the target address. The default value is
false.
Throws:
- FSException: If the source file type is different from the target file type, this exception is thrown. If
overwriteisfalseand the target address exists, this exception is thrown. - IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.
func exists(Path)
public func exists(path: Path): Bool
Description: Checks whether the target address exists.
Parameters:
- path: Path: target address to be checked
Returns:
- Bool: whether the target address exists
Throws:
- IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.
func exists(String)
public func exists(path: String): Bool
Description: Checks whether the target address exists.
Parameters:
- path: String: target address to be checked
Returns:
- Bool: whether the target address exists
Throws:
- IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.
func rename(Path, Path, Bool)
public func rename(sourcePath: Path, to!: Path, overwrite!: Bool = false): Unit
Description: Renames the file or directory specified by sourcePath to the name specified by to. sourcePath must be the path of an existing file or directory. If to is the path of an existing file or directory, the specific behavior is specified by overwrite. If overwrite is true, the existing file or directory is deleted and then renamed. Otherwise, an exception is thrown.
NOTE
When
overwriteistrue, an implicit behavior ofrenameis to delete the original file or directory in the target location. If the target location is a directory, all content in the directory will be deleted recursively. Therefore, exercise caution when performing this operation.
Parameters:
- sourcePath: Path: address to be renamed
- to!: Path: target address
- overwrite!: Bool: whether to overwrite the target address. The default value is
false.
Throws:
- FSException: When the operating system fails to execute the rename method, this exception is thrown.
- IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.
func rename(String, String, Bool)
public func rename(sourcePath: String, to!: String, overwrite!: Bool = false): Unit
Description: Renames the file or directory specified by sourcePath to the name specified by to. sourcePath must be the path of an existing file or directory. If to is the path of an existing file or directory, the specific behavior is specified by overwrite. If overwrite is true, the existing file or directory is deleted and then renamed. If overwrite is false, an exception is thrown.
NOTE
When
overwriteistrue, an implicit behavior ofrenameis to delete the original file or directory in the target location. If the target location is a directory, all content in the directory will be deleted recursively. Therefore, exercise caution when performing this operation.
Parameters:
- sourcePath: String: address to be renamed
- to!: String: target address
- overwrite!: Bool: whether to overwrite the target address. The default value is
false.
Throws:
- FSException: When the operating system fails to execute the rename method, this exception is thrown.
- IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.
func remove(Path, Bool)
public func remove(path: Path, recursive!: Bool = false): Unit
Description: Deletes a file or directory.
If the target is a folder, you can choose whether to delete the folder recursively.
Parameters:
- path: Path: target path
- recursive!: Bool: whether to delete a folder recursively. The default value is
false.
Throws:
- FSException: If the specified directory does not exist or fails to be deleted, this exception is thrown.
- IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.
func remove(String, Bool)
public func remove(path: String, recursive!: Bool = false): Unit
Description: Deletes a file or directory.
If the target is a folder, you can choose whether to delete the folder recursively.
Parameters:
- path: String: target path
- recursive!: Bool: whether to delete a folder recursively. The default value is
false.
Throws:
- FSException: If the specified directory does not exist or fails to be deleted, this exception is thrown.
- IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.
func removeIfExists(Path, Bool)
public func removeIfExists(path: Path, recursive!: Bool = false): Bool
Description: Checks whether the target exists. If it does, the remove method is executed and true is returned.
Parameters:
- path: Path: target path
- recursive!: Bool: whether to delete a folder recursively. The default value is
false.
Returns:
- Bool: whether the target address exists
Throws:
- FSException: If the target fails to be deleted, this exception is thrown.
- IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.
func removeIfExists(String, Bool)
public func removeIfExists(path: String, recursive!: Bool = false): Bool
Description: Checks whether the target exists. If it does, the remove method is executed and true is returned.
Parameters:
- path: String: target path
- recursive!: Bool: whether to delete a folder recursively. The default value is
false.
Returns:
- Bool: whether the target address exists
Throws:
- FSException: If the target fails to be deleted, this exception is thrown.
- IllegalArgumentException: If the path is empty or contains a string terminator, this exception is thrown.