在研發(fā)閑暇時(shí)間,將代碼過程經(jīng)常用的一些代碼段收藏起來,下邊代碼是關(guān)于Windows下Python獲取磁盤空閑空間并寫入日志的代碼,希望對各位朋友有較大用。
import time
import win32file文章來源:http://www.zghlxwxcb.cn/news/detail-401609.html
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文章來源地址http://www.zghlxwxcb.cn/news/detail-401609.html
到了這里,關(guān)于Windows下Python獲取磁盤空閑空間并寫入日志的代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!