because I can't do it! Stupid maths teacher didn't even teach us how to do this stuff.
Dude, what grade are you in? There is definetly something wrong with either mine or your education system. I remember doing this 3 - 4 years ago...(depends on which part do you find troublesome)
Ah... time passes quickly.( Sometimes I feel old. I wonder how old people feel..)
I'm going to assume that "Grade" in your country of origin means "Year" in mine (neither makes much sense if you think about it), so 11; and it's finding x without using a brute-force method that I didn't like doing.
In my country it is called 'class' for some reason (not in English). Every time someone asks 'what class are you in?' I get to guess what do they want to know.. Convenient.
No, this way I get five minutes just in case I made an accident :)
One of the many uses of a regular backup, which should be done regardless of whether you use the wastebasket or not.
I personally just delete stuff, no need for an undo mechanism, but I can always pull it out of the last backup if I do need it undone (though I can't remember having actually ever done that).
Level doesn't work, that's what some people call age! (I'm dead serious...people in my school will think of birthdays as "levelling up")
Seriously though, that script's a bit...absurd. I personally would have it check every 5 seconds or so, and if there's something in the bin, start the countdown to delete in 5 minutes. During the countdown, check every 5 seconds, and if the bin's empty, cancel.
import os
import time
trash = ".local/share/Trash/" # Location of trashcan
cmnd = "rm -rf " # This will change on non-*nix systems
def has_files(directory):
i, files, fname = 0, [], ""for fname in os.listdir(directory):
i += 1
print("Found file/dir %s" % fname)
return (False, True) [i > 0]
def clear(directory):
os.system(cmnd + directory + "*")
while True:
if has_files(trash): # Found files in trash directory
print("Found files in trash.")
time.sleep(300) # Sleep for 5 minutes
if has_files(trash) # Check again
print("Emptying trash...")
clear(trash) # Clear the folder
print("Done.")
else # Files must have been deleted externally...
print("Files appear to have been deleted.")
else:
print("No files found in trash...")
time.sleep(5) # Wait 5 seconds until next check
Only time I think a problem would come from that is when a person puts a file into the Bin, then undeletes it, and 4:59 later "deletes" something else accidentally and it vanishes.
Yep. What you should do is keep a map (or some other associative array) of filenames to times. After each second decrement all times by 1, and delete those that were 0 before the decrement.