How to delete a file without extension?

I created a function to delete files:

def deleteFile(deleteFile): if os.path.isfile(deleteFile): os.remove(deleteFile) 

However, when transferring the FIFO file name (without the file extension), this is not accepted by the os module. In particular, I have a subprocess that creates a FIFO file called "Testpipe". When called:

 os.path.isfile('Testpipe') 

This is the result of False . The file is not used / open or something like that. Python runs on Linux.

How can you delete such a file correctly?

+5
source share
1 answer

isfile checks for a regular file.

You can get around this this way 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) 
+6
source

Source: https://habr.com/ru/post/1258081/


All Articles