2014-11-03 89 views
0

这是我的基本层次... MYPROJECTS/MYRAILSAPP/source_code_folders在当前目录的父目录中创建新的目录 - ROR FileUtils.mkdir

  • 我有对我的ROR应用程序文件夹的MyProjects

  • 我应用程序源代码被称为MYRAILSAPP文件夹是MyProjects下

  • 的源代码内保持处于子目录中的MYRAILSAPP

我用FileUtils.mkdirMYRAILSAPP/app/controllers/files_controller.rb

class FilesController < ApplicationController 
    layout 'files' 
    def home 
    end 
    def index 
    if File.exist?('new') 

    else 
     files = Dir.glob('*') 
     FileUtils.mkdir 'new' 
     FileUtils.cp_r files, 'new' 
    end 
    end 
end 

这就造成了MYRAILSAPP一个新的目录,以便它是MYRAILSAPP/new

我想创建新的目录,以便它是MYPROJECTS/new

回答

2

要将该目录定义为路径名:

path = Rails.root.join('..', 'new') 

要在磁盘上创建:

path.mkpath 

要检查它是否已经存在:

path.exist? 

查看更多的事情可以做Pathname文档。

+0

现在很好,我也可以** FileUtils.cp_r **到'path' – 2014-11-04 07:06:06

相关问题