mkdir
-
PHP’s
mkdirfunction is used to create a new directory. An optional second argument specifies the permissions on the directory.PHP
mkdir('/path/to/new_dir', 0700);
Ruby’s
Dir.mkdirclass method works exactly the same way. Like PHP’smkdir, it also accepts an optional second argument for permissions.Ruby
Dir.mkdir('/path/to/new_dir', 0700)
One nice feature of the
mkdirfunction in PHP is that it supports an optional third argument,$recursive, that will recursively build directories likemkdir -pon the shell of Unix-like systems.PHP
mkdir('/path/to/new_dir', 0700, true);
Ruby’s
Dir.mkdirdoesn’t have a recursive mode. However, you can useFileUtilsfrom the Ruby Standard Library to make a directory (FileUtils.mkdir) and recursively make a directory (FileUtils.mkdir_p).Ruby
require 'fileutils' # make a directory FileUtils.mkdir('/path/to/new_dir') # recursively make a directory FileUtils.mkdir_p('/path/to/new_dir)
Both
FileUtils.mkdirandFileUtils.mkdir_pallow permissions to be optionally specified by supplying an options hash.Ruby
require 'fileutils' FileUtils.mkdir_p('/path/to/new_dir', :mode => 0700)
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.

