[Python] Windows下Python获取磁盘空闲空间并写入日志 →→→→→进入此内容的聊天室

来自 , 2021-03-07, 写在 Python, 查看 142 次.
URL http://www.code666.cn/view/6616758d
  1. from ctypes import *
  2. import time
  3. import win32file
  4.  
  5. run = True
  6. logfile = open('.\\log.out','w+');#open log file
  7. input = raw_input("Input a string for disk name like \'d:\' or other:")#input a disk name
  8. while run:
  9.         sectorsPerCluster, bytesPerSector, numFreeClusters, totalNumClusters = \
  10.                         win32file.GetDiskFreeSpace(input)
  11.         freespace = (numFreeClusters * sectorsPerCluster * bytesPerSector) /(1024 * 1024)#get free space
  12.         logfile.write("%s %s FreeSpace is %d MBytes\n" % (time.asctime(),input,freespace));#write log
  13.         print  time.asctime(),input,"FreeSpace is",freespace,"MBytes"#output to screen
  14.         time.sleep(3)#wait 3 second
  15. logfile.close();#close log file
  16. #//python/5800

回复 "Windows下Python获取磁盘空闲空间并写入日志"

这儿你可以回复上面这条便签

captcha