routine unlink

Documentation for routine unlink assembled from the following types:

class IO::Path

From IO::Path

Defined as:

method unlink(IO::Path:D: --> True)
sub    unlink(*@filenames --> List:D)

Delete all specified ordinary files, links, or symbolic links for which there are privileges to do so. See rmdir to delete directories.

The subroutine form returns the names of all the files in the list, excluding those for which the filesystem raised some error; since trying to delete a file that does not exist does not raise any error at that level, this list will include the names of the files in the list that do not exist.

The method form returns True on success, or fails with X::IO::Unlink if the operation could not be completed. If the file to be deleted does not exist, the routine treats it as success.

'foo.txt'.IO.open(:w).close;
'bar'.IO.mkdir;
say unlink <foo.txt  bar  not-there.txt># OUTPUT: «[foo.txt not-there.txt]␤» 
# `bar` is not in output because it failed to delete (it's a directory) 
# `not-there.txt` is present. It never existed, so that's deemed a success. 
 
# Method form `fail`s: 
say .exception.message without 'bar'.IO.unlink;
# OUTPUT: «Failed to remove the file […] illegal operation on a directory␤»