开发者

How to create a directory structure with Rake for a Rails project

I have a Rails 3 app which needs to have some directories created. I'd like to have a rake task which I can run to do this as a sort of initialization procedure. Basically I'd like to do: rake app:create_dirs or something similar. I tried using the "directory" commands but they seem to be only for dependencies in rake. Any ideas how to do this nicely? My dir structure needs to loo开发者_运维技巧k like this:

public/content/0/0

public/content/0/1

public/content/0/2

...

public/content/1/0

public/content/1/1

...

public/content/n/m

where n is 0..9 and m is 0..9

Thanks for any advice.


Something like this should work, I don't know your exact application but the main point is to look into FileUtils#mkdir_p

require 'fileutils'

(0..9).each do |n|
  (0..9).each do |m|
    FileUtils.mkdir_p("#{Rails.public_path}/content/#{n}/#{m}")
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜