Skip to content

File/Directory search pattern #70

@martindevans

Description

@martindevans

There is a difference between how the real FS does searchPatterns and how System.IO.Abstractions does them.

With a filesystem like this:

_fs = new MockFileSystem(new Dictionary<string, MockFileData>()
{
  { @"C:\Folder\a.foo", new MockFileData("aaa") },
  { @"C:\Folder\.foo\a.file", new MockFileData("bbb") }
}

Looking for *.foo we have two things, a file (a.foo) and a directory (C:\Folder.foo). However, this fails to find the directory (doing this in a similar setup in the real FS finds both):

    var dir = _fs.DirectoryInfo.FromDirectoryName("C:\\");
    var directories = dir.GetDirectories("*.foo");     //Nothing is found!

To make this work I need to use a slightly different search pattern:

*.foo\

Which finds the folder (but not the file a.foo).

I suspect the internal searching system (a quick glance shows it builds a regex) is being overly restrictive. The regex obviously wants directories (which are stored ending with a ) to have that double slash, even though windows file globs don't demand this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions