python实现--os模块使用(2)

# -*- coding: utf-8 -*-
"""
Created on Sun Feb  4 21:11:20 2018

@author: Administrator
计算输入文件目录下的所有文件的尺寸大小
"""

import os

def file_size(file_path):
    #拿到当前目录的所有内容的名称列表
    file_name_list = os.listdir(file_path)
    #遍历这个列表
    for enach in file_name_list:
        #拿到文件夹下所以内容的根目录
        file_name = os.path.join(file_path,enach)
        #判断是否是文件
        if os.path.isfile(file_name):
            print('文件名为:【'+enach+'】的大小为:'+str(os.path.getsize(file_name))+'Bytes')
    
file_path=input('请输入文件路径(例如:E:\\python3\\mywork\\first_project):')
file_size(file_path)

猜你喜欢

转载自blog.csdn.net/qq_34493908/article/details/79294501
今日推荐