From 9a8fb3dcf945d6b8bd2005ce99ce4017484d9a8b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 1 Nov 2022 09:41:40 -0500 Subject: add extensions for normalized path handling --- src/slskd/Common/CommonExtensions.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/slskd/Common/CommonExtensions.cs b/src/slskd/Common/CommonExtensions.cs index 29383fcb..ed07f9ea 100644 --- a/src/slskd/Common/CommonExtensions.cs +++ b/src/slskd/Common/CommonExtensions.cs @@ -301,6 +301,26 @@ namespace slskd return path.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar); } + /// + /// , but for paths normalized to use backslashes. + /// + /// + /// + public static string GetNormalizedDirectoryName(this string path) + { + return string.Join('\\', path.Split('\\').SkipLast(1)); + } + + /// + /// , but for paths normalized to use backslashes. + /// + /// + /// + public static string GetNormalizedFileName(this string path) + { + return string.Join('\\', path.Split('\\').TakeLast(1)); + } + /// /// Converts a fully qualified remote filename to a local filename, swapping directory characters for those specific /// to the local OS, removing any characters that are invalid for the local OS, and making the path relative to the -- cgit v1.2.3