I am trying to get the count of files in a folder and skip or execute the further resources based on the count.
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
But getting the following error
Chef::Exceptions::ValidationFailed: Property content must be one of: String, nil! You passed 0.
I am pretty new to chef and ruby so was wondering how to fix/solve this problem.
Once the count is obtained, how to check its value in other resources?
Also would like to know if this is the right approach.
Thanks
count
seems to be 0
(Fixnum).
You may wanna try:
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