Raymond Raymond - 2 years ago 95
Ruby Question

Open directory and create new file

I have this statement that creates nested directories:

require 'fileutils'
FileUtils::mkdir_p ''+project_name+'/new_folder'

I want to add for example a new file called
. Is there a way to accomplish that with Ruby?

Answer Source

You just need to do

path_name = "#{project_name}/new_folder"
FileUtils::mkdir_p path_name

This will create an empty file named README.md inside your project_name/new_folder directory.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download