I tried modifying your code with an intention to delete every file that i found to be below 250 bytes and also over 24 hours from the last time it was modified but im getting an error here.
forgive me if this is a silly one. im just not getting leads even from Google.
import sys
import os
from time import sleep
from datetime import datetime
path = "/home/pytbyte/Documents/cooperates contactslist.docx"
file_size = os.stat(path).st_size
f = open(path, 'r', 1)
bytes_read = 0
for line in f:
bytes_read += len(line)
percent = bytes_read * 100 / file_size
sys.stdout.write("\rpercentage: " + str(percent) + "%")
sys.stdout.flush()
sleep(1)
print
print "bytes_read:", bytes_read
print "file_size:", file_size
file_modified = datetime.datetime.fromtimestamp(os.path.getmtime(curpath))
if datetime.datetime.now() - file_modified > datetime.timedelta(hours=24):
os.remove(curpath)
if os.path.getsize(fullpath) < 200 * 1024:
os.remove(fullpath)
Those are so many mistakes, I suggest you learn programming instead of copy&pasting codes together without knowing what happens there.
However, I will tell you why it doesn't even run properly.
You use variables like curpath and fullpath that are not even defined. I can't tell you what they should be, only you can know.
You import the member datetime from datetime, yet you try to get the member datetime from datetime again. Doesn't make sense. Either do just "import datetime" or correct the calls "datetime.datetime.x" to just "datetime.x"
If you did all that it will run, but still not work as you intended. You just clashed some code pieces to getter that don't fit. That's not how you can achieve anything.
Also: Remove the sleep(1)
It was just for testing purposes as stated above.