0


Windows下Python获取磁盘空闲空间并写入日志的代码

在研发闲暇时间,将代码过程经常用的一些代码段收藏起来,下边代码是关于Windows下Python获取磁盘空闲空间并写入日志的代码,希望对各位朋友有较大用。

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)
logfile.write("%s %s FreeSpace is %d MBytesn" % (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

标签:

本文转载自: https://blog.csdn.net/weixin_44099735/article/details/122579262
版权归原作者 weixin_44099735 所有, 如有侵权,请联系我们删除。

“Windows下Python获取磁盘空闲空间并写入日志的代码”的评论:

还没有评论