How do I count the total number of lines of files in a given directory? in python -


how can use python count total number of lines in files in given directory?

in pseudo-code (non-executable):

total_length = 0 file_list = fetch_file_list()  # use: os.walk or glob.glob depending on whether want filter files. file_path in file_list:     file_path = make_path_absolute(file_path)     # can simple os.path.join(your_root_path, file_path)     file_object = open(file_path)      # don't forget there different modes -- files text?     total_length += length(file_object.readlines())      # might want consider: if of files large? print "there are", length(file_list), "files in", \     file_path, "containing", total_length, "lines of text." 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -