【问题标题】:Chef: Count the number of files in a folder厨师:计算文件夹中的文件数
【发布时间】:2017-11-09 06:23:12
【问题描述】:

我正在尝试获取文件夹中文件的计数,并根据计数跳过或执行更多资源。

file 'C:\Users\Desktop\Chef-file\count.txt' do
            dir = 'C:\Users\Desktop\Chef-Commands'
                count = Dir[File.join(dir, '**', '*')].count { |file| File.file?(file)}
              content count
            end

但出现以下错误

Chef::Exceptions::ValidationFailed: Property content must be one of: String, nil!  You passed 0.

我对 chef 和 ruby​​ 很陌生,所以想知道如何修复/解决这个问题。

得到count后,如何在其他资源中查看其值?

也想知道这是否是正确的方法。

谢谢

【问题讨论】:

    标签: ruby chef-infra chef-recipe cookbook


    【解决方案1】:

    count 似乎是 0 (Fixnum)。

    你可以试试:

    file 'C:\Users\Desktop\Chef-file\count.txt' do
      dir = 'C:\Users\Desktop\Chef-Commands'
      count = Dir[File.join(dir, '**', '*')].count { |file| File.file?(file)}
      content count.to_s
    end
    

    【讨论】:

    • 请记住,这将在编译时检查,也不会在收敛时检查。
    • 这行得通,但总是给出 0 作为文件数...需要弄清楚..
    猜你喜欢
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 2015-04-15
    • 2016-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多