1 Star 0 Fork 0

Shero / 第一周作业

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
2.py 657 Bytes
Copy Edit Web IDE Raw Blame History
Shero authored 2018-10-20 22:39 . 统计指定目录大小
print("====统计指定目录大小====")
import os
#计算指定目录大小函数
def dir_size(dir):
sum=0
if os.path.isfile(dir):
sum+=os.path.getsize(dir)
if os.path.isdir(dir):
ldir=os.listdir(dir)
for i in ldir:
file=os.path.join(dir,i)
if os.path.isdir(file):
sum+=dirsize(file)
if os.path.isfile(file):
sum+=os.path.getsize(file)
return sum
#输入需统计目录or文件
while True:
key_word = input("请输入指定文件目录的文件夹或文件(D:\Python或D:\Python\1.py),直接回车即退出:\n")
if key_word == "":
break
else:
print("{}字节".format(dir_size(key_word)))

Comment ( 0 )

Sign in for post a comment

Python
1
https://gitee.com/Chan_Shero/first_week_assignment.git
git@gitee.com:Chan_Shero/first_week_assignment.git
Chan_Shero
first_week_assignment
第一周作业
master

Search

103611 48b8ff67 1899542 103622 4d02230c 1899542