/// <summary> /// Cleans the directories matching the specified pattern. /// Cleaning the directory will remove all it's content but not the directory itself. /// </summary> /// <example> /// <code> /// CleanDirectories("./src/**/bin/debug"); /// </code> /// </example> /// <param name="env">The context.</param> /// <param name="pattern">The pattern to match.</param> /// <exception cref="InvalidOperationException">Cannot clean directory when <paramref name="env.FS"/> is null. /// </exception> public static void CleanDirectories(this IFileSystemEnvironment env, string pattern) { var directories = env.GetDirectories(pattern); if (directories.Count == 0) { return; } CleanDirectories(env, directories); }
/// <summary> /// Cleans the directories matching the specified pattern. /// Cleaning the directory will remove all it's content but not the directory itself. /// </summary> /// <example> /// <code> /// Func<IFileSystemInfo, bool> exclude_node_modules = /// fileSystemInfo=>!fileSystemInfo.Path.FullPath.EndsWith( /// "node_modules", /// StringComparison.OrdinalIgnoreCase); /// CleanDirectories("./src/**/bin/debug", exclude_node_modules); /// </code> /// </example> /// <param name="env">The context.</param> /// <param name="pattern">The pattern to match.</param> /// <param name="predicate">The predicate used to filter directories based on file system information.</param> /// <exception cref="InvalidOperationException">Cannot clean directory when <paramref name="env.FS"/> is null. /// </exception> public static void CleanDirectories(this IFileSystemEnvironment env, string pattern, Func <IFileSystemInfo, bool> predicate) { var directories = env.GetDirectories(pattern, predicate); if (directories.Count == 0) { return; } CleanDirectories(env, directories); }