Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grunt - delete all files and files in sub-directories with specific file extension

Tags:

gruntjs

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:

  • build/img/
  • build/img/ico
  • build/img/logos

and the file extension I want to delete is:

Any file with the extension of .png~, .gif~ or .jpg~

Any ideas?

like image 843
CLiown Avatar asked Jun 20 '13 20:06

CLiown


2 Answers

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.

like image 81
go-oleg Avatar answered Oct 31 '22 15:10

go-oleg


Easy, knee-jerk, response is to use Exec + a one line shell script like this one:

find . -name "*.png" -type f|xargs rm -f

like image 39
Adam Simpson Avatar answered Oct 31 '22 15:10

Adam Simpson