Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to use this vera++ tool against multiple *.cpp and *.h files. I accepts a filename as a parameter. How to search for *.cpp files and send them to vera++? Is this an one-liner or will I need a batch script?

share|improve this question
up vote 3 down vote accepted

Current folder only:

for %i in (*.cpp *.h) do vera++ "%~i"

Including subfolders:

for /r . %i in (*.cpp *.h) do vera++ "%~i"

/r . means "start in the current folder". If you want to specify a different folder name, use for /r newfolder.

share|improve this answer
How do I do that on Windows XP? It's not working. – Jader Dias Jun 13 '11 at 18:35
@Jader: How exactly is it not working? (Also, don't accept answers without testing them first.) – grawity Jun 13 '11 at 18:36
It works in the command line, but when inside a bat file it results ~i" was unexpected at this time (rough translation from portuguese) – Jader Dias Jun 13 '11 at 18:43
@Jader: When using for inside a batch file, you need to double the %s – like this: for %%i in (*.cpp *.h) do vera++ "%%~i" – grawity Jun 13 '11 at 18:51

It's a one-liner in the documentation, certainly. Here are the options:

  • Do what the documentation says. The documentation says
    find . -name '*.h' | xargs vera++ -profile my_favourite
    And with an appropriate toolset, such as Microsoft's own downloadable SFUA utility toolkit that runs on the Windows 7 Subsystem for UNIX-based Applications (which comes in the box with Windows 7 Ultimate edition and Windows Server 2008 R2 — For Windows XP, one can download and install Services for UNIX version 3.5.) one has tools such as find and xargs for Windows. There are, of course, also GNUWin32, cygwin, and unxutils.
  • If you are using JP Software's TCC/LE you can use the built-in SELECT command to interactively select the files to process:
    SELECT vera++ [*]
    Note the square brackets, which cause all of the filenames to be combined into one command.
  • Using an orthodox file manager, such as File Commander for Windows or FAR, you can similarly select the files to process interactively, and paste them onto the command line with the appropriate keypress.
  • If you are using JP Software's TCC/LE you can use the built-in FOR command to process files after finding them (say) with the DIR command:
    DIR /B /S *.cpp;*.h|FOR F IN (@CON) do vera++ %F
    or just process them directly since FOR has a recursion option:
    FOR /R F IN (*.cpp;*.h) DO vera++ %F
    This of course runs the command once per individual file found.
  • Or you can do what Grawity said.
share|improve this answer
it happens that windows xp already has a find.exe (for searching strings inside files) then you have to specify which find do you want to use – Jader Dias Jun 13 '11 at 19:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .