Count all lines of code from multiple .c files in a directory

Hello all! I study now a method to read all lines from a .c file . I don’t know how to write the function in python in a general way: if I have a directory that contains multiple .c files.
The scenario would be:
Folder name: src
Then file1: TxAcknowledge.c ( let’s say it should be 10 lines of code )
file2: IPcore.c ( 15 lines )
file3: aaabbb.c ( 20 lines )

the script should enter in src folder and check for all *.c files and count and print 10+15+20=45 lines of code as a total.

The path of src folder should be relative because it’s included in different upper paths like Module1\src… or Module2\src…

Thanks for help!

How about the following:

from pathlib import Path

def count_lines(paths):
    return sum(len(p.read_text().splitlines()) for p in paths)

path = "path_to_folder"  # path to the folder of interest
paths = Path(path).glob("**/*.c")  # search recursively for files ending with .c
count_lines(paths)