maid-example icon indicating copy to clipboard operation
maid-example copied to clipboard

Empty dir rule trashes any directories with square brackets in the name

Open mourner opened this issue 12 years ago • 4 comments

See http://stackoverflow.com/questions/14127343/why-dir-glob-in-ruby-doesnt-see-files-in-folders-named-with-square-brackets

mourner avatar Aug 07 '13 19:08 mourner

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?

benjaminoakes avatar Aug 07 '13 21:08 benjaminoakes

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

mourner avatar Aug 07 '13 22:08 mourner

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!

benjaminoakes avatar Aug 07 '13 22:08 benjaminoakes

Sure!

mourner avatar Aug 07 '13 22:08 mourner