Hi How can I delete a file after a certain time?

for example if I want to delete a file after 08.30 has passed?

do I use import OS? and import time?

Use the wait() method on a Threading.Event object or a Threading.Condition object, with a timeout.

Maybe this could help you to catch some file operation and using time.sleep:

import os
import time
dirname = 'test'

fn = os.path.join(dirname, 'test.txt')

with open(fn, 'w') as f: f.write('Nothing')
print 'Created %s (%s)' % (fn, time.asctime())

print os.listdir(dirname)

print os.listdir(dirname)
print 'Deleted %s (%s)' % (fn, time.asctime())

It must be in a function. I have 4 files that needs to be deleted within 4 different times. How can I do that then? Can I make it like:

def remove(filename,time)
                if time os.remove(filename)

I have dont know?

you can sort the times and wait for each time in turn.

What about if the python script not running???

I think you need a cron job. With cron job you are in win win situation for this operation.