Dennis Lee Bieber <[EMAIL PROTECTED]> writes: > On 26 Apr 2005 03:40:16 -0700, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > >> Hello Mike, >> I have to know this topic otherwise my program has to check whether the >> file / files are already deleted and this is a little bit messy. >> > Ah, but this requirement is different from the one you > originally asked. > > In either event, the best solution is probably to wrap the call > with a try block... > > try: > os.remove(fileName) > except <need to determine what errors can be raised>: > # do whatever you need for the error > except <other error>: > # do whatever this error needs... > > If the error is that the file didn't exist to be deleted, you > can probably use a "pass" as the except processing.
This is just a little bit tricky. os.remove (on FreeBSD 5-STABLE, anyway) throws an OSError exception if it doesn't have permission to remove the file, *or* if the file doesn't exist. You have to examine the exception for it's value, which is the result of a strerror call. I believe that the result of strerror is platform dependent. <mike -- Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list