Using c# GetDirectories to retrieving folders immediately under the search directory. The code works for all other directories searched EXCEPT a single directory. Specifically, GetDirectories returns two different folders, one contains the search pattern while the other one doesn't contain the search pattern.
Wildcard search pattern is *43*
in my example.
Tried pretty much everything I could think of.
Strangely, if I change the case of any one character of the "WINCE_TEST_IMAGE_41" folder name then the GetDirectories
returns the expected (and correct) single directory that matches the search pattern which is "*43*"
(again). For example, change the "C"
to a "c"
...then the single directory containing 43
is returned...
Setup:
I have .NET Framework SDK 4.8 installed (latest installation as of 9/3/2019).
1. Create folder "C:\Temp\WINCE_OS_IMAGES"
2. Create subfolders in folders named:
* "WINCE_TEST_IMAGE_40"
* "WINCE_TEST_IMAGE_41"
* "WINCE_TEST_IMAGE_42"
* "WINCE_TEST_IMAGE_43"
* "WINCE_TEST_IMAGE_44".
So that the directory structure is:
C:\Temp \WINCE_OS_IMAGES \WINCE_TEST_IMAGE40 \WINCE_TEST_IMAGE41 \WINCE_TEST_IMAGE42 \WINCE_TEST_IMAGE43 \WINCE_TEST_IMAGE44
Code:
v
is a parameter input to the method so I have assigned a value to help reproduce the issue.
string v = "43";
string[] dirs2 = Directory.GetDirectories(@"C:\Temp\WINCE_OS_IMAGES", "*" +
v + "*", SearchOption.TopDirectoryOnly);
foreach (string str in dirs2)
{
Console.WriteLine(str);
}
Expected:
GetDirectories
statement returns only the directory ending in "43"
.
Actual:
GetDirectories statement returns two directories, one ending in "41"
and the other ending in "43"
.