# File lib/bee_task.rb, line 104
      def filter_files(includes, excludes, root, dotmatch=true)
        error "includes must be a glob or a list of globs" unless
          !includes or includes.kind_of?(String) or includes.kind_of?(Array)
        error "excludes must be a glob or a list of globs" unless
          !excludes or excludes.kind_of?(String) or excludes.kind_of?(Array)
        error "root must be an existing directory" unless
          !root or File.exists?(root)
        current_dir = Dir.pwd
        begin
          if dotmatch
            options = File::FNM_PATHNAME | File::FNM_DOTMATCH
          else
            options = File::FNM_PATHNAME
          end
          Dir.chdir(root) if root
          included = []
          includes = '**/*' if not includes
          for include in includes
            error "includes must be a glob or a list of globs" unless
              include.kind_of?(String)
            # should expand directories ?
            # include = "#{include}/**/*" if File.directory?(include)
            entries = Dir.glob(include, options)
            included += entries if entries
          end
          included.uniq!
          if excludes
            included.reject! do |file|
              rejected = false
              for exclude in excludes
                if File.fnmatch?(exclude, file, options)
                  rejected = true
                  break
                end
              end
              rejected
            end
          end
          included.reject! { |file| File.directory?(file) }
          return included
        ensure
          Dir.chdir(current_dir)
        end
      end