Bug 42715 - Directory.GetFiles & AllDirectories might fail
Summary: Directory.GetFiles & AllDirectories might fail
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: master
Hardware: PC Windows
: Normal normal
Target Milestone: Future Release
Assignee: Alexander Köplinger [MSFT]
: 31885 ()
Depends on:
Reported: 2016-07-21 14:43 UTC by Miha Markic
Modified: 2016-12-02 00:15 UTC (History)
6 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Miha Markic 2016-07-21 14:43:16 UTC
Consider this 
Directory.GetFiles("ROOT", "something/else/*", SearchOption.AllDirectories)

This method will most likely fail, since GetFiles try to apply search pattern to every subdirectory of root, 
i.e. it will try
ROOT/something/something/else/*, not just ROOT/something/else/*.

Actual behavior: DirectoryNotFound exception is thrown.
Expecting all subdirectories of ROOT/something/else/ are traversed, not those of ROOT/.

.net version works as expected.

Observed on Android, but I guess it is mono library issue.
Comment 1 Blake Niemyjski 2016-07-21 15:01:52 UTC
I'm also seeing this issue using our .NET Standard lib.
Comment 2 Rodrigo Kumpera 2016-07-23 00:14:38 UTC
Test case:

using System;
using System.IO;

class Foo { 
	static void Main () {
		try {
			if (Directory.Exists ("testdir"))
				Directory.Delete ("testdir", true); 
			Directory.CreateDirectory ("testdir");
			Directory.CreateDirectory ("testdir/something");
			Directory.CreateDirectory ("testdir/something/else");
			File.WriteAllText ("testdir/something/else/file", "hello");
			var r = Directory.GetFiles("testdir", "something/else/*", SearchOption.AllDirectories);
			Console.WriteLine (r.Length == 1);
			Console.WriteLine (r[0] == Path.Combine ("testdir", "something", "else", "file"));
		} finally {
			Directory.Delete ("testdir", true);
Comment 3 Alexander Köplinger [MSFT] 2016-11-29 15:42:16 UTC
*** Bug 31885 has been marked as a duplicate of this bug. ***
Comment 4 Alexander Köplinger [MSFT] 2016-11-29 16:06:45 UTC
Implemented a fix in https://github.com/mono/mono/pull/4042.
Comment 5 Alexander Köplinger [MSFT] 2016-12-02 00:15:29 UTC
The PR was merged.