python的文件操作

import os
import sys
class LineCount:
    def getTime():
        return sys.version
    def listAllFiles(name):
        if name=="":
            return "file name can not be empty"
        else:
            count=0;
            dirs=os.listdir(name)
            for dir in dirs:
                fullPath=name+'\\'+dir
                if os.path.isdir(fullPath):
                    LineCount.listAllFiles(fullPath)
                else:
        
                    count=count+1
                    #print(fullPath)
            return count  

#use class
print(LineCount.getTime())
fileName=input("input the file folder name:")
print(LineCount.listAllFiles(fileName))

相关推荐