From 9f9efaf95fc95948482a4ed7e862b5e17f7608cd Mon Sep 17 00:00:00 2001 From: N00MKRAD Date: Mon, 17 May 2021 21:12:09 +0200 Subject: [PATCH] Also add ".old" to image sequence outputs if folder already exists --- Code/IO/IOUtils.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Code/IO/IOUtils.cs b/Code/IO/IOUtils.cs index 6945fd3..bf6e6ed 100644 --- a/Code/IO/IOUtils.cs +++ b/Code/IO/IOUtils.cs @@ -441,7 +441,7 @@ namespace Flowframes.IO } /// - /// Add ".old" suffix to existing files to avoid them being overwritten. If one already exists, it will be ".old.old" etc. + /// Add ".old" suffix to an existing file to avoid it getting overwritten. If one already exists, it will be ".old.old" etc. /// public static void RenameExistingFile(string path) { @@ -464,6 +464,29 @@ namespace Flowframes.IO } } + /// + /// Add ".old" suffix to an existing folder to avoid it getting overwritten. If one already exists, it will be ".old.old" etc. + /// + public static void RenameExistingFolder(string path) + { + if (!Directory.Exists(path)) + return; + + try + { + string renamedPath = path; + + while (Directory.Exists(renamedPath)) + renamedPath += ".old"; + + Directory.Move(path, renamedPath); + } + catch (Exception e) + { + Logger.Log($"RenameExistingFolder: Failed to rename '{path}': {e.Message}", true); + } + } + /// /// Easily rename a file without needing to specify the full move path ///