I want to view all the folders inside the directory:
directory\ folderA\ a.cpp folderB\ b.cpp folderC\ c.cpp folderD\ d.cpp
The name of the folders is known. In particular, I am trying to count the number of lines of code in each of the source files a.cpp , b.cpp , c.pp and d.cpp . So, go inside folderA and read a.cpp , count the lines, and then go back to the directory, go to folderB , read b.cpp , count the lines, etc.
This is what I had so far,
dir = directory_path for folder_name in folder_list(): dir = os.path.join(dir, folder_name) with open(dir) as file: source= file.read() c = source.count_lines()
but I'm new to Python and have no idea if my approach is appropriate and how to proceed. Any sample code would be appreciated!
Also, does with open open / close a file, as it should be for all of these readings, or does it take more processing?
source share