Why can I delete Open Image files in .NET using FileInfo?

I have a small utility that deletes files from folders using the .NET FileInfo.Delete () method. Basically, I can catch an IOException if the file is currently open. This works for all files except image files (jpg, gif, bmp, etc.). When these types of files are open, the program can still delete them without throwing any exceptions. Have you encountered this before? As it would be discovered that these file types are open so that I can prevent deletion.

Thanks Minh

+4
source share
2 answers

Whether it is possible to delete a file when it is open depends more on the program in which the file is open than the type of file. If the application, for example, simply reads the contents of the file and then closes the file (for example, Notepad), you can delete the file while it is "open" (which means that it is displayed in Notepad). On the other hand, Excel saves the file in an open way, which usually cannot even be copied.

+8
source

Use a tool such as WhoLockMe or Unlocker to see if the file is really β€œopen”. As others have said, this has nothing to do with the file type, but just as reading a program opens the file.

+1
source

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


All Articles