I have several sub-directories inside a parent directory that I need to remove using my cookbook, but there are many other sub-directories I need to keep. Is there a programmatic way I can achieve the delete of certain sub-directories or do I have to manually specify each one that I wish to remove like so;
directory "/var/lib/foo" do
action :delete
end
You could just specify a desired pattern with a regular expression and delete all (sub)directories matching that pattern.
Something like that:
Dir["/main/{sub1,sub2,sub3}"].each do |dir|
file ::File.expand_path(dir) do
action :delete
end
end
For more information on how to match the desired files using Dir see the Ruby docs on Dir.
This related SO question might also be useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With