unlink
-
The
unlinkfunction in PHP is used to delete a file from the filesystem. Ruby’sFile.unlinkclass method is equivalent.PHP
unlink('/path/to/foobar')
Ruby
File.unlink('/path/to/foobar')
File.unlinkis also aliased asFile.delete. Both are commonly used.In both the PHP and Ruby versions, the filename must refer to only a single file. For example,
foo*would not be a valid argument.Deleting Multiple Files
Ruby’s
File.unlinksupports variable arguments. You may specify multiple filenames to delete in a single call.Ruby
File.unlink('/path/to/foo', '/path/to/bar', '/path/to/baz')
Deleting by Pattern Match
An alternative to
File.unlinkisFileUtils.rm. You may pass either a string filename toFileUtils.rmor an array of filenames. This makes it especially useful for deleting multiple files when combined withDir.glob.Ruby
require 'fileutils' FileUtils.rm Dir.glob('/path/to/*')
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

