WGet.NET 4.4.1
A WinGet wrapper library for .Net.
Loading...
Searching...
No Matches
PathHelper.cs
1//--------------------------------------------------//
2// Created by basicx-StrgV //
3// https://github.com/basicx-StrgV/ //
4//--------------------------------------------------//
5using System.IO;
6
7namespace WGetNET.Helper
8{
12 internal static class PathHelper
13 {
17 public enum PathType
18 {
19 Generic,
20 URI,
21 Directory
22 }
23
36 public static string TrimLastPathPart(string path, PathType type)
37 {
38 char separatorChar = '/';
39 switch (type)
40 {
41 case PathType.URI:
42 separatorChar = '/';
43 break;
44 case PathType.Directory:
45 separatorChar = Path.DirectorySeparatorChar;
46 break;
47 }
48
49 int lastSeparatorIndex = -1;
50 for (int i = 0; i < path.Length; i++)
51 {
52 if (path[i].Equals(separatorChar))
53 {
54 lastSeparatorIndex = i;
55 }
56 }
57
58 if (lastSeparatorIndex > -1)
59 {
60#if NETCOREAPP3_1_OR_GREATER
61 return path[..lastSeparatorIndex];
62#elif NETSTANDARD2_0
63 return path.Remove(lastSeparatorIndex);
64#endif
65 }
66
67 return path;
68 }
69 }
70}