File.rm

You're seeing just the function rm, go back to File module for more information.

Specs

rm(Path.t()) :: :ok | {:error, posix()}

Tries to delete the file path.

Returns :ok if successful, or {:error, reason} if an error occurs.

Note the file is deleted even if in read-only mode.

Typical error reasons are:

  • :enoent - the file does not exist
  • :eacces - missing permission for the file or one of its parents
  • :eperm - the file is a directory and user is not super-user
  • :enotdir - a component of the file name is not a directory; on some platforms, :enoent is returned instead
  • :einval - filename had an improper type, such as tuple

Examples

File.rm("file.txt")
#=> :ok

File.rm("tmp_dir/")
#=> {:error, :eperm}