Empty dir rule trashes any directories with square brackets in the name
See http://stackoverflow.com/questions/14127343/why-dir-glob-in-ruby-doesnt-see-files-in-folders-named-with-square-brackets
Interesting. I won't have time to look at this until later, but is this a problem with my example Maid script? Or a problem in Maid itself?
It's just an example script problem. I fixed it by modifying the rule as follows:
def escape_glob(s)
s.gsub(/[\\\{\}\[\]\*\?]/) { |x| "\\"+x }
end
...
rule 'Remove empty directories' do
dir('~/Downloads/*').each do |path|
if File.directory?(path) and dir("#{escape_glob(path)}/*").empty?
trash(path)
end
end
end
Good to know. That seems like something that might be good for the Maid community at large. Would you be willing to contribute escape_glob in a pull request on benjaminoakes/maid?
Thanks for reporting this!
Sure!