Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
File.unlink
(*::path file_name) -> ::Integer
File.delete(*paths) → integer
File.unlink(*paths) → integer
file.c
View on GitHub ↗
static VALUE
rb_file_s_unlink(int argc, VALUE *argv, VALUE klass)
{
return apply2files(unlink_internal, argc, argv, 0);
}
Removes the entry (hard link) at each path in paths; returns the count of removed entries:
Example
filepath0 = '/tmp/t0.tmp' filepath1 = '/tmp/t1.tmp' File.write(filepath0, 'foo') File.write(filepath1, 'bar') File.unlink(filepath0, filepath1) # => 2
If the removed hard link is the last one associated with the inode, also removes the inode; otherwise, not. See Unlinking.
Does not follow symbolic links; if the entry is a symbolic link, removes the entry itself (not the link target).
Example
filepath = '/tmp/t.tmp' linkpath = '/tmp/link' File.write(filepath, 'foo') File.symlink(filepath, linkpath) File.unlink(linkpath) # => 1 File.exist?(filepath) # => true File.unlink(filepath) # => 1
Raises an exception on any error; some entries may have been deleted before the error occurs.