I have made a function for deleting files:
def deleteFile(deleteFile):
if os.path.isfile(deleteFile):
os.remove(deleteFile)
However, when passing a FIFO-filename (without file-extension), this is not accepted by the os-module. Specifically I have a subprocess create a FIFO-file named 'Testpipe'. When calling:
os.path.isfile('Testpipe')
It results to False
. The file is not in use/open or anything like that. Python runs under Linux.
How can you correctly delete a file like that?
isfile
checks for regular file.
You could workaround it like this by checking if it exists but not a directory or a symlink:
def deleteFile(filename):
if os.path.exists(filename) and not os.path.isdir(filename) and not os.path.islink(filename):
os.remove(filename)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With