CLOC- count lines of code, exclude everything in a dir except for certain files - cloc

I am using cloc to count our code. We need to exclude everything in a directory, except for files with a specific form like *instru.c. Is it possible to use the exclude and include files to do this?

Related

CLOC --diff and --exclude-dir don't seem to work together

I am trying to compare two directories with multiple subfolders. This is my CLOC script:
cloc-1.76.exe --diff test_initial test_latest --timeout 60 --exclude-dir=ZC_DATA --out=results.txt
Both folders have a ZC_DATA directory. In test_initial it is empty, in test_latest has several C and XML files, therefore lots of code to count.
What I am experiencing is that with or without the switch exclude-dir=ZC_DATA I am getting exactly the same results, no difference at all.
I need a way to include or exclude this folder in order to get different results.
Please advise.
Regards,
M.R.
If you do a straight count of one of the input directories, for example,
cloc-1.76.exe --timeout 60 --exclude-dir=ZC_DATA --out=results.txt test_latest
with and without --exclude-dir=ZC_DATA do the counts change? Repeat the two invocations with the second directory, test_initial, and report if there are differences there as well.
I'm trying to execute a cloc command with --diff AND --exclude-list-file and the files including in .clocignore are not ignored in the result.
Here the cmd:
os.system{'cloc --diff {} {} --exclude-list-file=.clocignore --by-file --out={} --csv'.format (directory1, directory2, output.loc)}
.clocignore file content:
/tmp/workspace/directory2/myfile.cpp
NOTE: this particular file (myfile.cpp) appears in directory2 but it does not exist in directory1.
If diff directory1 - directory2 is not successfully because some files in directory1 do not exist, the result are: the lines counted in directory2, which it is fine!
BUT,
it does not exclude the files contained in ..clocignore
why the --exclude-list-file=.clocignore is not working in this scenario?
Thanks,

Rename a «grandparent» folder case-sensitive?

How can I rename the folder called «grandparent» in the following directory structure
C:\Temp\grandparent\parent\child\
to «GrandParent» and
C:\Temp\GrandParent\parent\child\
The child-folder is not empty and contains different files.
If I try it with the command IO.Directory.Move(OldDirName, NewDirName) I get an error that the directory name must not be identical (ignoring the different case spelling).
Do I really have to move it to a completely new temporary directory (like C:\AnotherTemp\ and then move it back to the desired «GrandParent»?
(This answer seems only to work, if the last part («child») should be renamed.)

vb.net Exclude extension from "GetFiles"

I'm currently adding all found documents in a directory and sub-directory into a listbox.
This works perfectly, for my need, but i'm getting too much unwanted files.
The code for adding the files into my listbox:
ES_MAIN_SPECIFICATIONS_LIST.Items.AddRange(IO.Directory.GetFiles(oFolder, "*", IO.SearchOption.AllDirectories))
The * makes that all files are included but how can I exclude a certain extention?
You will need to then loop through again, removing those with the extensions you don't want. You can also use LINQ (.Where(...)) to do the same thing inline:
ES_MAIN_SPECIFICATIONS_LIST.Items.AddRange(IO.Directory.GetFiles(oFolder, "*", IO.SearchOption.AllDirectories).Where(Function(p) Not IO.Path.GetExtension(p).Equals("excludeMe"))

How to access two different routines in two files in Trace32 CMM scripts

I have two files in two different floder locations in Trace32. I execute cd.do file_name subroutine_name in Trace32. The trace32 takes the location of first command executed as the folder from which the following commands needs to be executed. How can I execute the routines from two different folders.
There is a pretty good guide here on how to script in Trace32.
http://www2.lauterbach.com/pdf/practice_user.pdf
I do not understand why you need to have them in two different folders, shouldn't it be solved by just have it in the same folder?
Well, maybe you should simply use DO <myscript.cmm> instead of CD.DO <myscript.cmm>.
DO <myscript.cmm> executes the script at the given location but keeps the current working path.
CD.DO <myscript.cmm> changes the working path to the location of the given script and then executes the script.
However I would recommend to write your scripts in a way that it doesn't matter if they are called with CD.DO or just DO. You can achieve that with either absolute paths or with paths relative to the script locations. (I prefer the 2nd one.)
So imagine the following file structure:
C:\t32\myscripts\start.cmm
C:\t32\myscripts\folder1\routines.cmm
C:\t32\myscripts\folder2\loadapp.cmm
C:\t32\myscripts\folder2\application.elf
You can cope this structure with absolute paths like that:
start.cmm:
DO "C:/t32/myscripts/folder1/routines.cmm" subroutine_A
DO "C:/t32/myscripts/folder2/loadapp.cmm"
folder2/loadapp.cmm:
Data.LOAD.Elf "C:/t32/myscripts/folder2/application.elf"
DO "C:/t32/myscripts/folder1/routines.cmm" subroutine_B
With relative paths you could use the prefix "~~~~" before accessing other files relative from the location of the currently executed PRACTICE script. The "~~~~" is replaced with the path of the currently executed script (just like "~" stands for your home directory.) There is also a function OS.PPD() which gives you the directory of the currently executed PRACTICE script.
So above situation with relative paths look like that:
start.cmm:
DO "~~~~/folder1/routines.cmm subroutine_A"
DO "~~~~/folder2/loadapp.cmm"
folder2/loadapp.cmm:
Data.LOAD.Elf "~~~~/application.elf"
DO "~~~~/../folder1/routines.cmm" subroutine_B

Editing multiple .htaccess files

We got around 500 websites on our server and all of them has their own user directory.
/home/siteA/public_html/
/home/siteB/public_html/
/home/siteC/public_html/
All of them has its own .htaccess file and its duplicated.
What i wanna do is comment out last row of each file. is it possible to do it without actually editing all files by hand.
Yes. Assuming you have a list of which directories are sites in say sites.txt, just loop over them like this:
while read sitename; do
sed -ri "$ s/(.+)/#\1/" /home/$sitename/.htaccess
done < sites.txt
Just make sure that you don't have a bunch of empty lines at the end of your files; this will comment out the last line, not the last line with content. If you need to do that, it will become much more difficult.