Ruby - File Directory Creating

Introduction

You use Dir.mkdir to create directories, like so:

Demo

Dir.mkdir("mynewdir")

Result

Once the directory has been created you can navigate to it with Dir.chdir.

You can specify absolute paths to create directories under other specific directories:

Demo

Dir.mkdir("/mynewdir") 
Dir.mkdir("c:\test")

Result

You cannot create directories under directories that don't yet exist themselves.

To create an entire structure of directories, you must create them one by one from the top down.

Related Topics