Using Python to achieve the size of the statistics folder, you need to use the OS module. The OS module provides a way to count file sizes: os.path.getsize (Dirpath)
The specific code is as follows:
ret = Os.sep.join (__file__. Split ('/') [:-2]) name=os.path.basename (ret) sum=0deffunc (Dirpath): LST= Os.listdir (Dirpath)#a list of files under a large folder, including folders forElinchLst:new_dir= dirpath+'\\'+ElifOs.path.isfile (new_dir): GetSize=os.path.getsize (New_dir)Globalsum sum+=GetSizeElse: Func (New_dir)returnSumnum=func (ret)Print('the size of the folder%s is%s bytes'% (Name,num))
total file size in the statistics folder
This statistic needs to use recursive thought, first obtains the folder path which needs the statistic size, obtains the folder all folders and the file, carries on the If judgment, if is the file, calculates the file size to add the sum, if is the folder, continues carries on the last step operation, the statistic internal file and the folder, Continue to judge. Until all of the traversal is complete, end the loop.
In this case, the last sum is the sum of all the files in the large folder.
To implement the total size of files in a simple statistics folder with Python