[Manu: it would help if you were to follow the convention on this list and post your answer underneath or within the text to which you're replying.]
[... description of removing files raising WindowsError 32 because the file is in use by another process ...] On 12/11/2013 12:32, manu agarwal wrote: > I caught the Exception using this code: > > try: > print(file) > os.remove(file) > continue > except WindowsError as e: > print e > But i am still not able to delete the files it only caught the exception > in the file and then the script terminates. > > Please let me know how can i proceed with the rest of the file to delete. If the file is in use, you won't be able to delete it. The best you can do is skip it, log it, perhaps retry or add it to a queue to revisit later. If some other process is holding it open, there's nothing you can do -- short of killing that process -- to delete the file out from under it. In your code above, the "continue" is doing nothing. If you were to put the "continue" inside your except handler, the loop could carry on, eg. <code> import os, glob for file in glob.glob("c:/temp/*.txt"): try: os.remove(file) except WindowsError as exc: print("Could not delete %s because %s" % (file, exc)) continue else: print("Deleted %s" % file) </code> TJG _______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32