File
file.copy
Copy a file. Arguments and implementation follows the POSIX cp command line specifications.
Type:
(?recursive : bool, ?force : bool, ?preserve : bool, string, string) -> unit
Arguments:
recursive(of typebool, which defaults tofalse): Copy file hierarchies.force(of typebool, which defaults totrue): If a file descriptor for a destination file cannot be obtained attempt to unlink the destination file and proceed.preserve(of typebool, which defaults tofalse): Duplicate source files attributes in the destination file.(unlabeled)(of typestring): Source(unlabeled)(of typestring): Destination
file.digest
Return an MD5 digest for the given file.
Type:
(string) -> string
Arguments:
(unlabeled)(of typestring)
file.exists
Returns true if the file or directory exists.
Type:
(string) -> bool
Arguments:
(unlabeled)(of typestring)
file.extension
Returns a file's extension.
Type:
(?dir_sep : string, ?leading_dot : bool, string) -> string
Arguments:
dir_sep(of typestring, which defaults to"/"): Directory separator.leading_dot(of typebool, which defaults totrue): Return extension with a leading dot, e.g..foo.(unlabeled)(of typestring)
file.is_directory
Returns true if the file exists and is a directory.
Type:
(string) -> bool
Arguments:
(unlabeled)(of typestring)
file.ls
List all the files in a directory.
Type:
(?absolute : bool, ?recursive : bool, ?pattern : string?, ?sorted : bool,
string) -> [string]
Arguments:
absolute(of typebool, which defaults tofalse): Whether to return absolute paths.recursive(of typebool, which defaults tofalse): Whether to look recursively in subdirectories.pattern(of typestring?, which defaults tonull): Pattern that the filenames should match (e.g."*.mp3").sorted(of typebool, which defaults tofalse): Return results in a sorted order.(unlabeled)(of typestring): Directory to look in.
file.metadata
Read metadata from a file.
Type:
(string, ?exclude : [string]) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.exclude(of type[string], which defaults to[]): Decoders to exclude
file.metadata.ffmpeg
Read metadata from a file using the ffmpeg decoder.
Type:
(string) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.
file.metadata.flac
Read metadata from a file using the flac decoder.
Type:
(string) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.
file.metadata.flac_native
Read metadata from a file using the flac_native decoder.
Type:
(string) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.
file.metadata.id3
Read metadata from a file using the id3 decoder.
Type:
(string) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.
file.metadata.id3v1
Read metadata from a file using the id3v1 decoder.
Type:
(string) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.
file.metadata.id3v2
Read metadata from a file using the id3v2 decoder.
Type:
(string) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.
file.metadata.image
Read metadata from a file using the image decoder.
Type:
(string) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.
file.metadata.mp4
Read metadata from a file using the mp4 decoder.
Type:
(string) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.
file.metadata.native
Read metadata from a file using the native decoder.
Type:
(string) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.
file.metadata.ogg
Read metadata from a file using the ogg decoder.
Type:
(string) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.
file.metadata.ogg_native
Read metadata from a file using the ogg_native decoder.
Type:
(string) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.
file.metadata.video-metadata
Read metadata from a file using the video-metadata decoder.
Type:
(string) -> [string * string]
Arguments:
(unlabeled)(of typestring): File from which the metadata should be read.
file.mime.magic
Get the MIME type of a file.
Type:
(string) -> string
Arguments:
(unlabeled)(of typestring)
file.mkdir
Create a directory.
Type:
(?parents : bool, ?perms : int, string) -> unit
Arguments:
parents(of typebool, which defaults tofalse): Also create parent directories if they do not exist.perms(of typeint, which defaults to0o755): Default file rights if created.(unlabeled)(of typestring)
file.move
Move a file
Type:
(?force : bool, ?atomic : bool, string, string) -> unit
Arguments:
force(of typebool, which defaults tofalse): Do not prompt for confirmation if the destination path exists.atomic(of typebool, which defaults tofalse): Move the file atomically. Impliesforceand raiseserror.file.cross_deviceif atomic move fails because the source and destination files are not on the same partition.(unlabeled)(of typestring): Source(unlabeled)(of typestring): Destination
file.mtime
Last modification time.
Type:
(string) -> float
Arguments:
(unlabeled)(of typestring)
file.open
Open a file.
Type:
(?write : bool, ?create : bool?, ?append : bool, ?non_blocking : bool,
?perms : int, string) -> socket
Arguments:
write(of typebool, which defaults tofalse): Open file for writingcreate(of typebool?, which defaults tonull): Create if nonexistent. Default:falsein read-only mode,truewhen writing.append(of typebool, which defaults tofalse): Append data if file exists.non_blocking(of typebool, which defaults tofalse): Open in non-blocking mode.perms(of typeint, which defaults to0o644): Default file rights if created.(unlabeled)(of typestring)
Methods:
close(of type() -> unit): Close the socket.closed(of type() -> bool):trueif the socket is already closed.non_blocking(of type(bool) -> unit): Set the non-blocking flag on the socketread(of type((?timeout : float?) -> string) .{wait : (?timeout : float?, (() -> unit)) -> unit}): Read data from a socket. Reading is done when the function returns an empty string"".type(of typestring): Socket typewrite(of type((?timeout : float?, string) -> unit) .{wait : (?timeout : float?, (() -> unit)) -> unit}): Write data to a socket
file.remove
Remove a file.
Type:
(string) -> unit
Arguments:
(unlabeled)(of typestring)
file.rmdir
Remove a directory and its content.
Type:
(string) -> unit
Arguments:
(unlabeled)(of typestring)
file.size
File size in bytes.
Type:
(string) -> int
Arguments:
(unlabeled)(of typestring)
file.temp
Return a fresh temporary filename. The temporary file is created empty, with permissions 0o600 (readable and writable only by the file owner).
Type:
(?directory : string?, string, string) -> string
Arguments:
directory(of typestring?, which defaults tonull): Directory where to create the file.(unlabeled)(of typestring): File prefix(unlabeled)(of typestring): File suffix
file.temp_dir
Return a fresh temporary directory name. The temporary directory is created empty, in the default tmp directory, with permissions 0o700 (readable, writable and listable only by the file owner).
Type:
(string, ?string) -> string
Arguments:
(unlabeled)(of typestring): Directory name prefix.(unlabeled)(of typestring, which defaults to""): Directory name suffix.
file.umask
Get the process's file mode creation mask.
Type:
() -> int
file.umask.set
Set process's file mode creation mask.
Type:
(int) -> unit
Arguments:
(unlabeled)(of typeint)
file.watch
Call a function when a file is modified. Returns unwatch function in unwatch method.
Type:
(string, (() -> unit)) -> unit
Arguments:
(unlabeled)(of typestring): File to watch.(unlabeled)(of type() -> unit): Handler function.
Methods:
unwatch(of type() -> unit): Function to remove the watch on the file.
file.which
file.which("progname") looks for an executable named "progname" using directories from the PATH environment variable and returns "" if it could not find one.
Type:
(string) -> string?
Arguments:
(unlabeled)(of typestring)
path.basename
Get the base name of a path, i.e. the name of the file without the full path. For instance file.basename("/tmp/folder/bla.mp3") returns "bla.mp3".
Type:
(string) -> string
Arguments:
(unlabeled)(of typestring)
path.concat
Concatenate two paths, using the appropriate directory separator.
Type:
(string, string) -> string
Arguments:
(unlabeled)(of typestring)(unlabeled)(of typestring)
path.dirname
Get the directory name of a path.
Type:
(string) -> string
Arguments:
(unlabeled)(of typestring)
path.home.unrelate
Expand path that start with '~' with the current home directory.
Type:
(string) -> string
Arguments:
(unlabeled)(of typestring)
path.remove_extension
Remove the file extension from a path.
Type:
(string) -> string
Arguments:
(unlabeled)(of typestring)