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

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


Attachments

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.

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

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.

Note You need to log in before you can comment on or make changes to this bug.