To gauge the space occupancy of a directory, Python offers several approaches. Below we delve into an efficient and comprehensive solution:
import os
def directory_size(start_path):
total_size = 0
for root, directories, files in os.walk(start_path):
for file in files:
file_path = os.path.join(root, file)
if not os.path.islink(file_path):
total_size = os.path.getsize(file_path)
return total_size
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3