rmdir
-
We can remove a directory in PHP using the
rmdirfunction. The directory must be empty and permissions must allow its removal.PHP
rmdir('/path/to/dir_to_remove');
Ruby’s
Dirclass provides two class methods,Dir.deleteandDir.rmdir, that are synonyms. Both are functionally equivalent to PHP’srmdir.Ruby
# identical Dir.delete('/path/to/dir_to_remove') Dir.rmdir('/path/to/dir_to_remove')
One drawback of both PHP’s
rmdirand the class methods provided by Ruby’sDirclass is that directory must be empty before it can be removed.You can remove a non-empty directory, in the same way as you would with
rm -rfon the shell of a Unix-like system, by usingFileUtils.rm_rf.Ruby
require 'fileutils' FileUtils.rm_rf('/path/to/dir_to_remove')
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.

