Skip to content

Commit c6b198e

Browse files
committed
feat: Keep the root output directory in DocumentSet.Save()
Instead of deleteing the output directory recursively in DocumentSet.Save(), delete all child directories and files, but keep the root output directory as it would be recreated afterwards anyways. Closes #12
1 parent 189059f commit c6b198e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/MarkdownGenerator/Extensions/_Admonition/MdAdmonition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Grynwald.MarkdownGenerator.Extensions
77
/// <summary>
88
/// Represents a "admonition" in a markdown document implemented by
99
/// the "Admonition" extension for Python-Markdown.
10-
/// For details https://python-markdown.github.io/extensions/admonition/
10+
/// For details see https://python-markdown.github.io/extensions/admonition/
1111
/// </summary>
1212
/// <remarks>
1313
/// Using this element will produce markdown which will not be rendered correctly

src/MarkdownGenerator/_Model/DocumentSet.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,22 @@ public void Save(string directoryPath, bool cleanOutputDirectory, Action<T, stri
198198
if (directoryPath == null)
199199
throw new ArgumentNullException(nameof(directoryPath));
200200

201+
// If selected, delete all files and directories in the output directory
202+
// Keep the root output directory unchanged (it would be recreated
203+
// directly afterwards anyways). By keeping the directory
204+
// we won't run into problems when an application still
205+
// has the directory open.
201206
if (Directory.Exists(directoryPath) && cleanOutputDirectory)
202207
{
203-
Directory.Delete(directoryPath, recursive: true);
208+
foreach(var childDir in Directory.GetDirectories(directoryPath))
209+
{
210+
Directory.Delete(childDir, recursive: true);
211+
}
212+
213+
foreach(var file in Directory.GetFiles(directoryPath))
214+
{
215+
File.Delete(file);
216+
}
204217
}
205218

206219
foreach (var keyValuePair in m_DocumentsByPath)

0 commit comments

Comments
 (0)