The std.io
module provides functions for file system operations and standard input/output.
Reads the entire contents of a file into a string.
Parameters:
path
: The path to the file to readReturn Type: string
Example:
Reads all lines from a file and returns them as a single string with newlines.
Parameters:
path
: The path to the file to readReturn Type: string
Example:
Writes a string to a file, creating the file if it doesn't exist or overwriting it if it does.
Parameters:
path
: The path to the file to writecontent
: The string content to write to the fileReturn Type: boolean
Example:
Appends a string to the end of a file, creating the file if it doesn't exist.
Parameters:
path
: The path to the file to append tocontent
: The string content to append to the fileReturn Type: boolean
Example:
Reads a line of input from standard input. If a prompt is provided, it will be displayed before reading input.
Parameters:
prompt
(optional): A string to display as a promptReturn Type: string
Example:
Checks if a file or directory exists at the specified path.
Parameters:
path
: The path to checkReturn Type: boolean
Example:
Checks if the path points to a file.
Parameters:
path
: The path to checkReturn Type: boolean
Example:
Checks if the path points to a directory.
Parameters:
path
: The path to checkReturn Type: boolean
Example:
Creates a directory and all its parent directories if they don't exist.
Parameters:
path
: The path of the directory to createReturn Type: boolean
Example:
Removes a file from the file system.
Parameters:
path
: The path of the file to removeReturn Type: boolean
Example:
Removes a directory from the file system.
Parameters:
path
: The path of the directory to removerecursive
(optional): If true, removes the directory and all its contents recursively. Default is false.Return Type: boolean
Example:
Renames a file or directory.
Parameters:
from
: The current pathto
: The new pathReturn Type: boolean
Example: