Delete a File

From Erlang Community

[edit] Problem

You want to delete a file.

[edit] Solution

Use Erlang's standard function file:delete.

1> file:delete("/this/file/will/soon/be/gone.txt").
ok

The function deletes the file with the given pathname, if it exists, returning ok if a file was deleted successfully, otherwise an error is returned.

[edit] Discussion

Note that if you wish to delete a directory, you should use the corresponding function file:del_dir.

2> file:del_dir("/this/dir/will/soon/be/gone").
ok

The function deletes the given directory if it exists, returning ok if successful. An error will be returned if any part of the directory path is not a directory.

Erlang/OTP Projects
Personal tools