From cade3fdfaae9318a579ed597bc1c0aa4f8702cad Mon Sep 17 00:00:00 2001 From: adroslice Date: Thu, 14 Nov 2019 15:14:21 +0100 Subject: [PATCH] Added File Data Model - Stores the components of a full file path - Larger components (FullName, Path) can both be retrieved and set - Stores all of the initial values for comparison, displaying before and after using a single list property, and reverting changes --- DataModels/FileModel.cs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 DataModels/FileModel.cs diff --git a/DataModels/FileModel.cs b/DataModels/FileModel.cs new file mode 100644 index 0000000..0b85136 --- /dev/null +++ b/DataModels/FileModel.cs @@ -0,0 +1,39 @@ +namespace BulkFileRenamer.DataModels +{ + public class FileModel + { + public string OldName { get; } + public string OldFullName { get; } + public string OldExtension { get; } + public string OldDirectory { get; } + public string OldPath { get; } + + public string Name { get; set; } + public string Extension { get; set; } + public string Directory { get; set; } + + public string FullName + { + get => Extension != "" ? $"{Name}.{Extension}" : Name; + set + { + Name = value.LastIndexOf('.') >= 0 ? value.Substring(0, value.LastIndexOf('.')) : value; + Extension = value.LastIndexOf('.') >= 0 ? value.Substring(value.LastIndexOf('.') + 1, value.Length - value.LastIndexOf('.') - 1) : ""; + } + } + + public string Path + { + get => $"{Directory}{FullName}"; + set + { + FullName = value.Substring(value.LastIndexOf('\\') + 1); + Directory = value.Substring(0, value.LastIndexOf('\\') + 1); + } + } + + public FileModel(string path) => + (OldPath, OldExtension, OldFullName, OldDirectory, OldName) = + (Path = path, Extension, FullName, Directory, Name); + } +}