OS independent file paths & Utility.PathCombine added
System.IO.Path.Combine provides cross-platform support for system paths, however rooted paths discarding of earlier segments Utilities.PathCombine ensures if any parameters start with root chacters does not discard previous Utilities.PathCombine allows appending of "\\" to translate to the correct cross-platform result
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@ -236,5 +237,21 @@ namespace Oqtane.Shared
|
||||
@"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
|
||||
RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250));
|
||||
}
|
||||
|
||||
public static string PathCombine(params string[] segments)
|
||||
{
|
||||
var separators = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };
|
||||
|
||||
for (int i =1;i < segments.Length; i++){
|
||||
if(Path.IsPathRooted(segments[i])){
|
||||
segments[i] = segments[i].TrimStart(separators);
|
||||
if(String.IsNullOrEmpty(segments[i])){
|
||||
segments[i]=" ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Path.Combine(segments).TrimEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user