diff --git a/BFR/Operations/Number.cs b/BFR/Operations/Number.cs index d51f34b..e24b98b 100644 --- a/BFR/Operations/Number.cs +++ b/BFR/Operations/Number.cs @@ -1,10 +1,12 @@ -using System.Xml.Serialization; +using System.Linq; +using System.Xml.Serialization; using System.Collections.Generic; using Avalonia; using BFR.Helpers; using BFR.DataModels; +using System; namespace BFR.Operations { @@ -36,6 +38,16 @@ namespace BFR.Operations ? (StartIndex + Increment * (files.Count - 1)).ToString().Length : Padding; + // Fail conditions: Out of bounds insert + var shortestLength = files.Min(x => FullName ? x.FullName.Length : x.Name.Length); + if (Mode == NumberMode.Insert && InsertPosition > shortestLength) throw new OperationException($"First N can't be greater than the shortest file name length ({shortestLength})."); + + // Regex Failure + if (Mode == NumberMode.Replace && UseRegex) + try { "".Replace(Pattern, "", true, false); } + catch (Exception) { throw new OperationException("Invalid Regex Pattern."); } + + // Apply operation foreach (var file in files) { var newName = FullName ? file.FullName : file.Name;