Skip to main content
Version: 2.5.x (dev)

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 type bool, which defaults to false): Copy file hierarchies.
  • force (of type bool, which defaults to true): If a file descriptor for a destination file cannot be obtained attempt to unlink the destination file and proceed.
  • preserve (of type bool, which defaults to false): Duplicate source files attributes in the destination file.
  • (unlabeled) (of type string): Source
  • (unlabeled) (of type string): Destination

file.digest

Return an MD5 digest for the given file.

Type:

(string) -> string

Arguments:

  • (unlabeled) (of type string)

file.exists

Returns true if the file or directory exists.

Type:

(string) -> bool

Arguments:

  • (unlabeled) (of type string)

file.extension

Returns a file's extension.

Type:

(?dir_sep : string, ?leading_dot : bool, string) -> string

Arguments:

  • dir_sep (of type string, which defaults to "/"): Directory separator.
  • leading_dot (of type bool, which defaults to true): Return extension with a leading dot, e.g. .foo.
  • (unlabeled) (of type string)

file.is_directory

Returns true if the file exists and is a directory.

Type:

(string) -> bool

Arguments:

  • (unlabeled) (of type string)

file.ls

List all the files in a directory.

Type:

(?absolute : bool, ?recursive : bool, ?pattern : string?, ?sorted : bool,
string) -> [string]

Arguments:

  • absolute (of type bool, which defaults to false): Whether to return absolute paths.
  • recursive (of type bool, which defaults to false): Whether to look recursively in subdirectories.
  • pattern (of type string?, which defaults to null): Pattern that the filenames should match (e.g. "*.mp3").
  • sorted (of type bool, which defaults to false): Return results in a sorted order.
  • (unlabeled) (of type string): Directory to look in.

file.metadata

Read metadata from a file.

Type:

(string, ?exclude : [string]) -> [string * string]

Arguments:

  • (unlabeled) (of type string): 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 type string): 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 type string): 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 type string): 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 type string): 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 type string): 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 type string): 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 type string): 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 type string): 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 type string): 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 type string): 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 type string): 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 type string): File from which the metadata should be read.

file.mime.magic

Get the MIME type of a file.

Type:

(string) -> string

Arguments:

  • (unlabeled) (of type string)

file.mkdir

Create a directory.

Type:

(?parents : bool, ?perms : int, string) -> unit

Arguments:

  • parents (of type bool, which defaults to false): Also create parent directories if they do not exist.
  • perms (of type int, which defaults to 0o755): Default file rights if created.
  • (unlabeled) (of type string)

file.move

Move a file

Type:

(?force : bool, ?atomic : bool, string, string) -> unit

Arguments:

  • force (of type bool, which defaults to false): Do not prompt for confirmation if the destination path exists.
  • atomic (of type bool, which defaults to false): Move the file atomically. Implies force and raises error.file.cross_device if atomic move fails because the source and destination files are not on the same partition.
  • (unlabeled) (of type string): Source
  • (unlabeled) (of type string): Destination

file.mtime

Last modification time.

Type:

(string) -> float

Arguments:

  • (unlabeled) (of type string)

file.open

Open a file.

Type:

(?write : bool, ?create : bool?, ?append : bool, ?non_blocking : bool,
?perms : int, string) -> socket

Arguments:

  • write (of type bool, which defaults to false): Open file for writing
  • create (of type bool?, which defaults to null): Create if nonexistent. Default: false in read-only mode, true when writing.
  • append (of type bool, which defaults to false): Append data if file exists.
  • non_blocking (of type bool, which defaults to false): Open in non-blocking mode.
  • perms (of type int, which defaults to 0o644): Default file rights if created.
  • (unlabeled) (of type string)

Methods:

  • close (of type () -> unit): Close the socket.
  • closed (of type () -> bool): true if the socket is already closed.
  • non_blocking (of type (bool) -> unit): Set the non-blocking flag on the socket
  • read (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 type string): Socket type
  • write (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 type string)

file.rmdir

Remove a directory and its content.

Type:

(string) -> unit

Arguments:

  • (unlabeled) (of type string)

file.size

File size in bytes.

Type:

(string) -> int

Arguments:

  • (unlabeled) (of type string)

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 type string?, which defaults to null): Directory where to create the file.
  • (unlabeled) (of type string): File prefix
  • (unlabeled) (of type string): 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 type string): Directory name prefix.
  • (unlabeled) (of type string, 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 type int)

file.watch

Call a function when a file is modified. Returns unwatch function in unwatch method.

Type:

(string, (() -> unit)) -> unit

Arguments:

  • (unlabeled) (of type string): 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 type string)

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 type string)

path.concat

Concatenate two paths, using the appropriate directory separator.

Type:

(string, string) -> string

Arguments:

  • (unlabeled) (of type string)
  • (unlabeled) (of type string)

path.dirname

Get the directory name of a path.

Type:

(string) -> string

Arguments:

  • (unlabeled) (of type string)

path.home.unrelate

Expand path that start with '~' with the current home directory.

Type:

(string) -> string

Arguments:

  • (unlabeled) (of type string)

path.remove_extension

Remove the file extension from a path.

Type:

(string) -> string

Arguments:

  • (unlabeled) (of type string)