Windows下Python获取磁盘空闲空间并写入日志,python空闲,from ctypes


from ctypes import *import timeimport win32filerun = Truelogfile = open('.\\log.out','w+');#open log fileinput = raw_input("Input a string for disk name like \'d:\' or other:")#input a disk namewhile 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 secondlogfile.close();#close log file

评论关闭