How to make wx.FileDialog(wx.FD_OPEN mode) check input file name extension against the wildcard?

StackOverflow https://stackoverflow.com/questions/18501677

  •  26-06-2022
  •  | 
  •  

Question

I noticed that even if you set your wildcard to match *.txt files only, all wx.FileDialog does is list all txt files under that directory, still you can input any existent file with a different extension and hit open button without having any problem at all?

There doesn't seem to exist a window style to avoid this from happening, so I guess you have to validate the file extension yourself, right? Interesting, does this count as a bug?

Était-ce utile?

La solution

This is not exclusive to wxPython and is not a bug. Try this in any Windows application and you will see you can save a txt file as a .exe in Notepad or open a .png file in MS Word. A file extension is just a convention, which means it can be broken for any number of reasons. If you are confident that you must check the file extension of a file, you will need to perform some validation with the return value of the wx.FileDialog.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top