For testing purposes, I want to create a little utility which will prompt me for the size of a file I want to create and the location I want to send it to, then record the amount of time it takes to create the file, before logging the results on an Excel spreadsheet. So far I have this:
import time
import pythoncom
from win32com.client import Dispatch
#create file
myPath = input('Where do you want to write the file?')
size_MB = int(input('What sized file do you want to test with? (MB)'))
size_B = size_MB * 1024 * 1024
fName = '\pydatafile'
#start timer
start = time.clock()
f = open(myPath + fName,'w')
f.write("\x00" * size_B)
f.close()
#how much time it took
elapsed = (time.clock() -start)
print ("It took", elapsed, "seconds to write the", size_B, "MB file")
#I'll sort something out to work out Mbps when the rest is ready
#record results on Excel
xl = Dispatch('Excel.Application')
xl.visible= 0
wb = xl.Workbooks.Add(r'C:\Users\ryansinfield\Desktop\Book1.xlsm')
ws = wb.Worksheets(1)
#loop until empty cell is found in column
col = 1
row = 1
empty = False
while not empty:
val = ws.Cells(row,col).value
print("Looking for next available cell to write to...")
if val == None:
print("Writing result to cell")
ws.Cells(row,col).value = Mbps
empty = True
row += 1
xl.Run('Save')
xl.Quit()
pythoncom.CoUninitialize()
This creates a file to the specified location ok, but the file creation is instant. It doesn't matter what size I specify for the file it will always appear as 0 bytes and take microseconds to create.
Is there any way I can create an actual file which will allow me to test the LAN speed more effectively?
EDIT: It seems to be working now in terms of speed. I don't know why it just is, maybe I was being a numpty. However there's something I want to add. Is it possible to delete the blank file once the test has been run?