Python3.3下测试通过 获取文件大小 使用os.path.getsize函数,参数是文件的路径 获取文件夹大小 import os from os.path import join, getsize def getdirsize(dir): size = 0.0 for root, dirs, files in os.walk(dir): size += sum([getsize(join(root, name)) for name in files]) return size if __
1 #获取文件夹内的图片 2 import os 3 def get_imlist(path): 4 return [os.path.join(path,f) for f in os.listdir(path) if f.endswith('.jpg')] 5 6 img_path = get_imlist("database") 7 print(img_path)
1, 使用文件 #vim /etc/motd "1 hello world" 2 ...... yes 3 no you are a shadiao 4 hahh maye you are right ddddddddddddddddddddddddddddddddddd ccccccccccccc vvv 2,python脚本 [root@localhost python]# vim 7.py f=open("/etc/motd") alllines = [lin
import os totalSize = 0 fileNum = 0 dirNum = 0 def visitDir(path): global totalSize global fileNum global dirNum for lists in os.listdir(path): sub_path = os.path.join(path, lists) print(sub_path) if os.path.isfile(sub_path): fileNum = fileNum+1 # 统计
__author__ = 'bruce' import os from os.path import join,getsize def getdirsize(dir): size=0l for (root,dirs,files) in os.walk(dir): for name in files: try: #print getsize(join(root,name)) size += getsize(join(root,name)) except: continue #直接用下面这句代码,在