实现根据磁盘剩余容量,对剩余容量(预留了1GB)进行多次的写入和删除数据(次数为变量counts
)
每次写入1GB的数据(即变量data
),多次操作,以实现上述功能
通过更改taskTimes
变量可以多次写入和删除
from _datetime import datetime
import shutil
import os
def writeEraseDisk():
startTimeStamp = datetime.timestamp(datetime.now())
data = "*" * 1024 * 1024 * 1024 * 1
tmpFileName = "tmpFile"
if os.path.exists(tmpFileName):
os.remove(tmpFileName)
total, used, free = shutil.disk_usage("/")
print("The free disk space is [{} byte]({} GB)".format