Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporary file not deletable?

I have create the temporary file using the tempfile.mkstemp() and after creating this, I have get the unique path of the file inside the path and now I want to delete the temporary file. My code is given below.

I have already visit this WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'new.dat' but did not solve my problem.

Code

import os
import tempfile

path=tempfile.mkstemp('.png', 'bingo',
    'C:\\Users\\MuhammadUsman\\Documents\\PythonScripts\\Project')
os.unlink(path)

Error

PermissionError: [WinError 32] The process cannot access the file
because it is being used by another process:
'C:\\Users\\MuhammadUsman\\Documents\\PythonScripts\\Project\\bingois3q1b3u.png'
like image 282
Ishmal Ijaz Avatar asked Mar 08 '26 12:03

Ishmal Ijaz


1 Answers

Try this: this works for me.

import os
import tempfile

fd,path=tempfile.mkstemp('.png', 'bingo', 'C:\\Users\\MuhammadUsman\\Documents\\Python Scripts\\Project')
os.close(fd)
os.unlink(path)
like image 86
Muhammad Usman Avatar answered Mar 11 '26 00:03

Muhammad Usman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!