0

I wanted to run the cppcheck only for specific type of files and not all files.

For example, I want to run cppcheck for all files ending with "Operation.cpp" recursively (basically for *Operation.cpp). I don't find an option in cppcheck, doing the same. Could anyone help?

Also, can I grep if a function is present in the CPP file, and throw error, if it is not present in those files.

1 Answers1

3

On Linux you can use

find foo*.cpp | xargs cppcheck

This is an update, previous example used ls, but as noticed by more experienced people, for automation purposes find should be preferable solution. Proof: Why you shouldn't parse the output of ls(1)

grapes
  • 8,185
  • 1
  • 19
  • 31
  • Why `ls`? `echo` would be just enough. Don't parse the output of `ls`. If so, why not just `cppcheck foo*.cpp` ? – KamilCuk Dec 18 '18 at 10:47
  • This `ls` is an example. You can use additional options for ls, like recursive search in subfolders, that is what leverages it. Btw, how does `echo` help? – grapes Dec 18 '18 at 10:54
  • [Why you shouldn't parse the output of ls(1)](https://mywiki.wooledge.org/ParsingLs) Use `find` for recursive searches. `ls`is pretty printing. – KamilCuk Dec 18 '18 at 11:14