在一个目录中创建多个文件夹

时间:2015-12-05 21:34:02

标签: ruby fileutils

我正在尝试使用尽可能少的LOC构建一个简单的文件结构, 我知道FileUtils.mkdir_p './this/that/the/other'是一条道路。 Ruby中是否有任何内容可以在一个目录中创建多个文件夹,如FileUtils.mkdir_p './this/{that, foo, bar}/the/other(这不起作用)?

2 个答案:

答案 0 :(得分:1)

    #include <stdio.h>

int main() 
{
    int x;
    scanf("%d", &x);
    printf("%d", x);
    return 0;
}

注意双引号,它们允许字符串插值(在字符串中执行代码)。

答案 1 :(得分:0)

你可以这样做

%w[this that next].each{|dir| Dir.mkdir "/path/to/somewhere/#{dir}"}

这将创建/path/to/somewhere/this/path/to/somewhere/that/path/to/somewhere/next文件夹。

顺便说一句,您一次只能创建一个文件夹。即你必须创建一个文件夹./foo,然后./foo/bar,然后./foo/bar/next

它与ruby无关,它是OS工作的常用方式

相关问题