By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,667 Members | 1,347 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,667 IT Pros & Developers. It's quick & easy.

WindowsError: [Error 32] The process cannot access the file.

P: 5
I am getting the below error while executing the script on one of the application server.

WindowsError: [Error 32] The process cannot access the file because it is being used by another process

Script used to delete the files from the server.

I had used os.remove(file) and tried with os.unlink(file). But it is giving me the same error.

Is there any way i can skip the files which can not be deleted and script proceed further to delete other files or it delete the files forcely without giving this error.

I know the process which was using the files but i cannot stop that service because it will impact the application.

I tried with Catching the Exception but that also doesnt help.

Is there any way i could get the list of files which i am not able to delete from the directory then delete the rest one.

Attached is the code which i am executing.

Thanks
Attached Files
File Type: txt bo_del.txt (1.0 KB, 583 views)
Nov 13 '13 #1
Share this Question
Share on Google+
1 Reply

bvdet
Expert Mod 2.5K+
P: 2,851
There is no way to determine if a file is being used by another process in Windows that I am aware of. I am surprised it did not work by catching the exception. It works in this example:
Expand|Select|Wrap|Line Numbers
  1. >>> for i in range(4):
  2. ...     try:
  3. ...         os.remove(fn)
  4. ...     except WindowsError as e:
  5. ...         print e
  6. ...     
  7. [Error 32] The process cannot access the file because it is being used by another process: 'text.txt'
  8. [Error 32] The process cannot access the file because it is being used by another process: 'text.txt'
  9. [Error 32] The process cannot access the file because it is being used by another process: 'text.txt'
  10. [Error 32] The process cannot access the file because it is being used by another process: 'text.txt'
Nov 13 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.