diff --git a/src/msw/dir.cpp b/src/msw/dir.cpp index 5b05d23d48..691f732937 100644 --- a/src/msw/dir.cpp +++ b/src/msw/dir.cpp @@ -86,7 +86,13 @@ CheckFoundMatch(const FIND_STRUCT* finddata, const wxString& filter) // However if the filter contains only special characters (which is a // common case), we can skip the case conversion. if ( filter.find_first_not_of(wxS("*?.")) == wxString::npos ) - return fn.Matches(filter); + { + // And maybe even skip the check entirely if we have a filter that we + // know matches everything. This is more than just an optimization, as + // "*.*" it wouldn't match the files without extension according to + // wxString::Matches(), but it should. + return filter == wxS("*.*") || filter == wxS("*") || fn.Matches(filter); + } return fn.MakeUpper().Matches(filter.Upper()); } diff --git a/tests/file/dir.cpp b/tests/file/dir.cpp index ae5b81c5d5..5d11f80a52 100644 --- a/tests/file/dir.cpp +++ b/tests/file/dir.cpp @@ -20,6 +20,16 @@ #define DIRTEST_FOLDER wxString("dirTest_folder") #define SEP wxFileName::GetPathSeparator() +// We can't use wxFileSelectorDefaultWildcardStr from wxCore here, so define +// our own. +const char WILDCARD_ALL[] = +#if defined(__WXMSW__) +"*.*" +#else // Unix/Mac +"*" +#endif +; + // ---------------------------------------------------------------------------- // test fixture // ---------------------------------------------------------------------------- @@ -145,6 +155,9 @@ TEST_CASE_METHOD(DirTestCase, "Dir::Traverse", "[dir]") wxArrayString files; CHECK( wxDir::GetAllFiles(DIRTEST_FOLDER, &files) == 4 ); + // enum all files using an explicit wildcard + CHECK(wxDir::GetAllFiles(DIRTEST_FOLDER, &files, WILDCARD_ALL) == 4); + // enum all files according to the filter CHECK( wxDir::GetAllFiles(DIRTEST_FOLDER, &files, "*.foo") == 1 );