#-*- coding:cp936 -*-
import os, re
"""檢視資料夾下的所有檔案及資料夾 join為拼接函式
"""def look_file(path):
for root , dirs, files in os.walk(path, true):
print root #主目錄
for item in files: #主目錄下的資料夾
print os.path.join(root, item)
"""計算資料夾 大小
"""
def filesize(path):
size = 0l
for root , dirs, files in os.walk(path, true):
size += sum([os.path.getsize(os.path.join(root, name)) for name in files]) #目錄下檔案大小累加
return size
if __name__ == '__main__':
look_file("f://a")
print filesize("f://a")
計算資料夾大小
下面分享給大家2個封裝好的計算快取大小的方法 如 nsstring cachespath nssearchpathfordirectoriesindomains nscachesdirectory nsuserdomainmask yes lastobject 是沙盒資料夾中 lidrary中的ca...
遍歷資料夾
function search path string filename string ball boolean false string varsearchrec tsearchrec begin if findfirst path faanyfile,searchrec 0 then begin...
資料夾遍歷
c 遍歷指定資料夾中的所有檔案 directoryinfo thefolder new directoryinfo folderfullname 遍歷一層資料夾 foreach directoryinfo nextfolder in thefolder.getdirectories 遍歷多層資料夾 ...