I've had similar problem: I wanted my build to fail if there are files with the same file names detected in given path pattern. I have solved it by writing custom task. You could use grunt.file.expand or grunt.file.recurse GruntAPI
Maybe this will help you (this is coffeescript rather than js).
grunt.registerMultiTask "noduplicates", "Detects duplicated filenames", () ->
path = require('path')
dupFilenamesCounted = {}
haveDuplicates = false
options =
cwd: this.data.cwd
grunt.file.expand(options, this.data.src).forEach (filepath) ->
filepathParts = filepath.split(path.sep)
filename = filepathParts.slice(-1).join(path.sep)
unless dupFilenamesCounted[filename] is undefined
dupFilenamesCounted[filename].counter++
dupFilenamesCounted[filename].filepaths.push(filepath)
else
dupFilenamesCounted[filename] = { counter: 0, filepaths: [ filepath ] }
for filename of dupFilenamesCounted
if dupFilenamesCounted[filename].counter > 0
grunt.log.error "Filename: " + filename + ' has ' + dupFilenamesCounted[filename].counter + ' duplicates: ' + dupFilenamesCounted[filename].filepaths
haveDuplicates = true
# Fail by returning false if this task had errors
return false if haveDuplicates
Then you define your task:
noduplicates:
images:
cwd: '<%= pkg.src %>'
src: [ 'static/**/*.{gif,png,jpg,jpeg}' ]