【发布时间】:2017-12-05 11:52:28
【问题描述】:
我正在使用 Python 2.7 来监控在 Windows 2012 服务器上运行的某些应用程序的磁盘使用情况。如何获取位于例如此处的某些网络存储文件夹的大小:
\\storage\my_folder\
我尝试过使用(来自这篇文章:calculating-a-directory-size-using-python):
import os
def getFolderSize(folder):
total_size = os.path.getsize(folder)
for item in os.listdir(folder):
itempath = os.path.join(folder, item)
if os.path.isfile(itempath):
total_size += os.path.getsize(itempath)
elif os.path.isdir(itempath):
total_size += getFolderSize(itempath)
return total_size
当然不支持网络路径。
【问题讨论】:
-
我必须将网络驱动器映射到本地字母才能使某些脚本正常工作。
标签: python