I am working on a Python program that will make infinite text files on a flash drive. This program will be the only thing operating on that flash drive, and I want to check if there is sufficient storage space each time it writes.
If there is, I want to write the file to the drive. If there isn't enough space, I want to do something else with the contents. For example:
def write_file(contents):
if "Check if there is sufficient storage space on E:\ drive.":
with open("filename", "w") as file:
file.write(contents)
else:
# Alternative method for dealing with content.
I need to have a good way to find how much space a file.write()
operation will take and compare that with the free space on the drive.
Thank you!