SLOC count with Python
I am new to Beyond Compare so bare with me. I am currently brainstorming a Python code that will read in all the source files from a directory (including source files from subfolders) in a network, take the physical SLOC (Source Line of Code) count for each file, then sum them up and output it on a xml file.
From what I have read on the "Automating with Scripts" page, it does not seem BC3 has a library set that I can use on other languages like Python. So what I will probably have to do is write a BC script to take in all the source files from a directory, then get and output the SLOC count. Then write a Python code to run the script, then parse the SLOC counts from the output file, add all the SLOC counts up (unless I can get the total SLOC count directly), and generate an xml file with that info. Do you think that is the most logical way of doing things?
I am not entirely sure what BC scripts are capable of, like what functions to use to get all the files from a directory. Also, I don't need to compare any files. I just need the SLOC counts. I guess I could name the same directory twice, but it seems redundant.
Any help is appreciated.
Thank you for your suggestion! Much is appreciated! It really helped me a lot. Since there is no API, what I ended up doing on Python is to generate a bcscript.txt file and a batch file to execute the script, and it worked great. This is my output:
This is pretty much what I wanted. However, bcscript.txt, cmdBCScript.bat, rawSLOC.csv, and SLOCCounter.py should not be counted because those are not the source files. Those are files I am using to get my SLOC count. I was wondering if there are any BC script commands to filter specific files names. It should also not read in file with the *.txt extension, so I was wondering how to filter those out also. So really, the only file that should have been counted for is the findDup.cpp.
Use the filter command to limit the files affected by the script.
text-report layout:summary output-tout.txt
Filters can be file masks or exact filenames, with multiple filters separated by semicolons.
Chris K Scooter Software
You can also use "filter *.cpp" to only see files with .cpp extensions.
Chris K Scooter Software
Thanks, Chris! My program is running perfectly. I just found the "Scripting Reference" page too at the support reference, so I will look more into it other scripting functions.