I need to delete all files with a specific file extension in a directory and all of its sub-directories using Grunt.js and I guess I probably need a module to do so? I've looked at clean but that seems to be for deleting whole directories rather than specific files.
My directory looks like:
and the file extension I want to delete is:
Any file with the extension of .png~
, .gif~
or .jpg~
Any ideas?
You can configure the grunt-contrib-clean
task to remove those files like this:
clean : {
yourTarget : {
src : [ "build/img/**/*.png~",
"build/img/**/*.gif~",
"build/img/**/*.jpg~"
]
}
}
See this section of the docs for an explanation of **
, *
, and other globbing patterns.
Easy, knee-jerk, response is to use Exec + a one line shell script like this one:
find . -name "*.png" -type f|xargs rm -f
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