Python获取磁盘空闲空间并写入日志
2012-11-25 20:43
375 查看
from ctypes import * import time import win32file run = True logfile = open('.\\log.out','w+');#open log file input = raw_input("Input a string for disk name like \'d:\' or other:")#input a disk name while run: sectorsPerCluster, bytesPerSector, numFreeClusters, totalNumClusters = \ win32file.GetDiskFreeSpace(input) freespace = (numFreeClusters * sectorsPerCluster * bytesPerSector) /(1024 * 1024)#get free space logfile.write("%s %s FreeSpace is %d MBytes\n" % (time.asctime(),input,freespace));#write log print time.asctime(),input,"FreeSpace is",freespace,"MBytes"#output to screen time.sleep(3)#wait 3 second logfile.close();#close log file
![](http://img.my.csdn.net/uploads/201211/25/1353847740_3854.jpg)
运行环境:python-2.7.3 + pywin32-218.win32-py2.7
相关文章推荐
- Python实现获取磁盘剩余空间的2种方法
- 两种方法,获取磁盘剩余空间--PYTHON
- MFC 获取除C盘外,其余磁盘的总空间,及空闲空间
- 一次Mysql数据库服务器磁盘空间满引发的写入和同步问题
- C# 如何获取磁盘剩余空间
- python实现磁盘日志清理
- 学习python获取系统信息和磁盘容量
- C++ 获取机器的mac地址、获取字符串长度、写入日志等常用函数
- python执行shell获取硬件参数写入mysql的方法
- Python 获取接口数据,解析JSON,写入文件
- 获取系统URL访问的前三名(通过Scala方式实现/通过Spark方式实现),Spark将URL访问日志进行分类并通过自定义Partitioner的方式将文件写入到不同分区上
- python通过查找注册表的方式获取盘符(磁盘列表)
- 获取磁盘空间大小
- 如何用idapython脚本获取字符串窗口的数据并写入文件
- MS Sql Server查询磁盘的可用空间,数据库数据文件及日志文件的大小及利用率
- disk.py――获取磁盘空间
- linux omfs文件系统利用bitmap管理空闲磁盘空间
- python 获得磁盘空间 statvfs
- python 获取文件名称和读取写入文件小结
- PowerShell脚本获取磁盘空间两例