In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "python3 how to view folder size". Xiaobian shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "python3 how to view folder size" can help you solve the problem.
Specific operation method:
1. First, you need to import the os module into the python script for file operations.
import os
2, and then traverse all the contents of the folder by using the os.walk function.
3. After traversing the folder, you can sum all file sizes statistically.
The code example is as follows:
import os
from os.path import join, getsize
def getdirsize(dir):
size = 0
for root, dirs, files in os.walk(dir):
size += sum([getsize(join(root, name)) for name in files])
return size
if __name__ == '__main__':
size = getdirsize(r'D:\yisu')
print('There are %.3f' % (size / 1024 / 1024), 'Mbytes in D:\\yisu')\
Related operations:
Use the os.path.getsize ('file path') method to get the file size.
import os #import os module
os.path.getsize('d:/bin/yisu.txt ') #Get the specified file size
1329925
About "python3 how to view folder size" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.