In working on a script that computes, and outputs to a file, the total cyclomatic complexities of a project under test, I am trying to filter out files whose names (including path) contains "test". (Such files only exist for testing purposes, and are therefore exempt from computation.)
So far, I have the following code:
rem write temporary file, to append command line output to
SETLOCAL
SET tmpfile=tmp_ComplexityAnalysis.txt
echo. 2>%tmpfile%
rem perform cyclomatic complexity analysis on all the files, iff those files are not test files and have some functions in them
echo %tmpfile%
for /R apiserver_sdk %%G in (*.go) DO (
rem filter out "test" files
gocyclo %%G >> %tmpfile%
)
I don't know how to exclude "test" or where.
UPDATE: Changing the body of the for loop to :
DIR /A %%G| findstr test
IF %ERRORLEVEL% NEQ 0 (
rem filter out "test" files
gocyclo %%G >> %tmpfile%
)
doesn't work because, somehow, %ERRORLEVEL%
is always zero.
%ErrorLevel%
is always zero. I get the same result withfind
. Thegrep.exe
port of the Unix utility gives the correct return status, but I'm looking for a work-round using standard commands. I need to go out now: if no-one has come with an answer by the time I get back, I'll look into it further. By the way, why useDIR /A %%G|...
, rather thanecho %%G|...
?