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

百般思念 提交于 2019-12-06 18:31:47

问题


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?


回答1:


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.




回答2:


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

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



来源:https://stackoverflow.com/questions/17223237/grunt-delete-all-files-and-files-in-sub-directories-with-specific-file-extensi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!