About recursive function that returns the value of learning

# About the function returns the value of the question key points; who calls back to whom: by recursive function query folder size of the problem of all files to analyze: 
# OS module: View a folder all the files in this folder there are folders, not with Walk
# - Coding: UTF-8 -
Import os
Import SYS
#C: \ the Users \ Administrator \ Desktop \ Excel
the PATH = r'C: \ the Users \ Administrator \ Desktop \ Excel '
# write this function essential knowledge :
# Print (os.getcwd ()) # get the current path
# print (os.sep) # get the system path separator
# returns the specified directory of all the files and folders (directories): os.listdir (the pATH)
# test to out of the path is based on the file: os.path.isfile (the pATH)
# verify that the absolute path: os.path.isabs ()
path # test given if there is: os.path.exists ()
# returns a path directory name and file name: os.path.split ()
# separate extension: os.path.splitext ()
# get the path name: os.path.dirname ()
# get the file name: os.path.basename ()
# get file size: os.path.getsize (filename)

#os modules: calculating a folder for all files Size, this folder also folders, not Walk
# - * - Coding: UTF8 - * -
Import os
DEF lookfile (the PATH):
SUM = 0
File = os.listdir (the PATH) # get the folders and files under the path


for i in File:

RET = os.path.join ( the PATH, I)
IF os.path.isdir (RET):

RET1 = lookfile (RET)
SUM = + RET1
the else:
fsize = os.path.getsize (RET)
fsize = fsize / a float (1024 * 1024)
SUM = + fsize


return SUM


= lookfile RET (the PATH)
Print (RET)
Import time
# extended learning
# 1, '' 'into the timestamp time: 2016-11-16 10:53:12 to 1,479,264,792' ''
# DEF TimeStampToTime (timestamp):
# timeStruct = time.localtime (timestamp)
The time.strftime return # ( '% Y-M-% D%% H:% M:% S', timeStruct)
#
# 2, '' 'get file size, the result of two decimal places, the unit is MB' ' '
# DEF get_FileSize (filePath):
# = ilePath Unicode (filePath,' UTF8 ')
#
# = fsize os.path.getsize (filePath)
# = fsize fsize / a float (1024 * 1024)
# round return (fsize, 2)
#
# 3, '' 'to obtain file access time' ''
# DEF get_FileAccessTime (filePath):
# = filePath Unicode (filePath 'UTF8')
#
# T = os.path.getatime (filePath)
# TimeStampToTime return (T )
#
'get file creation time of the' # 4, '' ''
#     def get_FileCreateTime(filePath):
Unicode filePath = # (filePath, 'UTF8')
#
# T = os.path.getctime (filePath)
# TimeStampToTime return (T)
#
'Get file modification time' #. 5, '' ''
# DEF get_FileModifyTime (filePath) :
# = filePath Unicode (filePath, 'UTF8')
#
# T = os.path.getmtime (filePath)
# TimeStampToTime return (T)

Guess you like

Origin www.cnblogs.com/pushuiyu/p/12511114.html