如何使用 Rake 为 Rails 项目创建目录结构
我有一个 Rails 3 应用程序,需要创建一些目录。我想要一个 rake 任务,我可以运行它来执行此操作,作为一种初始化过程。基本上我想做:rake app:create_dirs
或类似的事情。我尝试使用“目录”命令,但它们似乎仅适用于 rake 中的依赖项。有什么想法可以很好地做到这一点吗?我的目录结构需要如下所示:
public/content/0/0
public/content/0/1
public/content/0/2
...
public/content/1/0
public/content/1/1
...
public/content/n/m
其中 n
是 0..9
, m
是 0..9
>
感谢您的任何建议。
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 look 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西应该有效,我不知道你的确切应用程序,但要点是研究 FileUtils#mkdir_p
Something like this should work, I don't know your exact application but the main point is to look into FileUtils#mkdir_p