1

The .NET documentation for MatchType.Win32 for Net-Core and Net 5+ versions says:

Match using Win32 DOS style matching semantics.
'*', '?', '<', '>', and '"' are all considered wildcards. Matches in a traditional DOS / Windows command prompt way.

https://learn.microsoft.com/en-us/dotnet/api/system.io.matchtype?view=net-6.0

How do you use the syntax for the '<' and '>' wildcards? I can not find that anywhere and the only thing I can find about DOS is the '*' and '?' wildcards. I know in Windows Explorer you can do a search like "date:>01/01/2021" but that is more of an operator than a wildcard and gives a syntax exception if using it with

var query = Directory.EnumerateDirectories(
       basefolder,
       "date:>01/01/2021", 
       new EnumerationOptions() { MatchType = MatchType.Win32 });

Passing regular old "*" as searchPattern still returns all entries, trying to pass "<" or ">" alone as searchPattern did not produce any results on folders I tried.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
stymie2
  • 101
  • 10
  • `date:>01/01/2021` is a feature of the command-line `dir` command, it is entirely separate from Win32's directory-enumeration code. – Dai Feb 03 '22 at 01:01
  • The logic for handling `<` and `>` is documented in inline comments here: https://github.com/dotnet/runtime/blob/c5c7967ddccc46c84c98c0e8c7e00c3009c65894/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemName.cs – Dai Feb 03 '22 at 01:06

2 Answers2

2

The logic for handling < and > is documented in inline comments here: https://github.com/dotnet/runtime/blob/c5c7967ddccc46c84c98c0e8c7e00c3009c65894/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemName.cs

Specifically:

https://github.com/dotnet/runtime/blob/c5c7967ddccc46c84c98c0e8c7e00c3009c65894/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemName.cs#L272

// '<' (DOS_STAR) matches any character except '.' zero or more times.`
// If we are at a period, determine if we are allowed to consume it, i.e. make sure it is not the last one.

https://github.com/dotnet/runtime/blob/c5c7967ddccc46c84c98c0e8c7e00c3009c65894/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemName.cs#L309

// '>' (DOS_QM) is the most complicated. If the name is finished, // we can match zero characters. If this name is a '.', we don't match, but look at the next expression. Otherwise we match a single character.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Dai
  • 141,631
  • 28
  • 261
  • 374
-3

Only two wildcards can be used in your case here: * and ?

Maybe you could consider using a few Linq expressions to filter the returned collection ?

I think it is more precise if the timezone is important to you in your code.

Rivo R.
  • 1
  • 2