rmdir

  • We can remove a directory in PHP using the rmdir function. The directory must be empty and permissions must allow its removal.

    PHP

    rmdir('/path/to/dir_to_remove');

    Ruby’s Dir class provides two class methods, Dir.delete and Dir.rmdir, that are synonyms. Both are functionally equivalent to PHP’s rmdir.

    Ruby

    # identical
    Dir.delete('/path/to/dir_to_remove')
    Dir.rmdir('/path/to/dir_to_remove')

    One drawback of both PHP’s rmdir and the class methods provided by Ruby’s Dir class 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 -rf on the shell of a Unix-like system, by using FileUtils.rm_rf.

    Ruby

    require 'fileutils'
     
    FileUtils.rm_rf('/path/to/dir_to_remove')

    see also

rewind rtrim

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.