/// <summary> /// Initializes a new instance of <see cref="MultiFileSource"/>. /// In case of usage from Maml, the paths would be wildcard concatenated in the first string of <paramref name="paths"/>. /// </summary> /// <param name="paths">The paths of the files to load.</param> public MultiFileSource(params string[] paths) { Contracts.CheckValueOrNull(paths); // calling the ctor passing null, creates an array of 1, null element // The types using MFS know how to account for an empty path // if the paths array is empty, therefore keeping that behavior. if (paths == null || (paths.Length == 1 && paths[0] == null)) { _paths = new string[0]; return; } // in case of usage from Maml, the paths would be wildcard concatenated in the // first string of paths. string[] concatenated = paths[0] != null?StreamUtils.ExpandWildCards(paths[0]) : null; if (concatenated != null && concatenated.Length > 1) { if (paths.Length > 1) { throw Contracts.Except($"Pass a single string to the {nameof(MultiFileSource)} constructor, if you are using wildcards."); } _paths = concatenated; } else { _paths = paths; } }
/// <summary> /// Checks the validity of a given path, and whether or not it is a /// valid path to a data file, or a path to a directory of files. /// </summary> /// <param name="path">Specifies a file or path of files from which to load.</param> private static void CheckValidPathContents(string path) { Contracts.CheckNonEmpty(path, nameof(path)); if (!File.Exists(path) && StreamUtils.ExpandWildCards(path).Length < 1) { throw Contracts.ExceptParam(nameof(path), "File or directory does not exist at path: {0}", path); } }
public MultiFileSource(string path) { Contracts.CheckValueOrNull(path); if (string.IsNullOrEmpty(path)) { _paths = new string[0]; return; } _paths = StreamUtils.ExpandWildCards(path); if (_paths.Length == 0) { throw Contracts.ExceptIO("Could not find file '{0}'", path); } }
/// <summary> /// Initializes a new instance of <see cref="MultiFileSource"/>. /// In case of usage from Maml, the paths would be wildcard concatenated in the first string of <paramref name="paths"/>. /// </summary> /// <param name="paths">The paths of the files to load.</param> /// <remarks> /// The provided <paramref name="paths"/> can utilize wildcards to load all source files. For example: /// paths = "Data/*" includes all files in directory Data /// paths = "DataFolder/.../*" includes all files in all subdirectories inside directory Data. /// paths = "Data1/*", "Data2/*" includes all files in directories Data1 and Data2 /// </remarks> public MultiFileSource(params string[] paths) { Contracts.CheckValueOrNull(paths); // calling the ctor passing null, creates an array of 1, null element // The types using MFS know how to account for an empty path // if the paths array is empty, therefore keeping that behavior. if (paths == null || (paths.Length == 1 && paths[0] == null)) { _paths = new string[0]; return; } List <string> concatenated = new List <string>(); if (paths != null) { foreach (string path in paths) { foreach (string rPath in StreamUtils.ExpandWildCards(path)) { concatenated.Add(rPath); } } } else { concatenated = null; } if (concatenated != null && concatenated.Count > 0) { _paths = concatenated.ToArray(); } else { _paths = paths; } }