Python implements the total number of rows in the. h and. cpp files under the Computing folder _python

Source: Internet
Author: User

Usually I wrote a lot of code, but never a good calculation of the total number of lines written, interview was asked up, silly ... Have nothing to do, write a python program to count

Import OS

################################################################################
def calcLine ( BaseDir):
  linecount = 0

  try: For
    fileName in Os.listdir (baseDir):

      fullpath = baseDir + filename
      if Os.path.isdir (fullpath):
        linecount + = calcline (fullpath + ' \ \ ") #递归读取所有文件
        
      if Os.path.splitext (FullPath) [1] in (". h", ". cpp"):
        file = open (FullPath) for
        eachline in File.readline ():
          linecount + = 1
        file.close ()
        
  except Exception as E:
    print (e) return
  linecount

############################################ ####################################
If __name__ = = "__main__":
  baseDir = "k:\\c++\\mfc\\bubbledragon\\"
  LineCount = Calcline (baseDir)
  print (LineCount)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.