Tinkr2/4.2/AphelionCore/AphelionCore/Helpers/Strings.cs
/// <summary>
/// Return absolute path from relative path
/// </summary>
/// <param name="baseDirectory">Base (or current) directory to use when assembling absolute path</param>
/// <param name="target">Relative path to convert</param>
/// <returns>Returns the absolute path</returns>
Return absolute path from relative path
Return absolute path from relative path
public static string AbsolutePath(string baseDirectory, string target)
      {
         if (baseDirectory.Substring(baseDirectory.Length - 1) == "\\")
         {
            baseDirectory = baseDirectory.Substring(0, baseDirectory.Length - 1);
         }
         if (target.Substring(0, 1) == "\\")
         {
            return target;
         }
         while (target.IndexOf("..\\") >= 0)
         {
            int i = baseDirectory.LastIndexOf("\\");
            if (i <= 0)
            {
               return target;
            }
            baseDirectory = baseDirectory.Substring(0, i);
            target = target.Substring(3);
         }
         return NormalizeDirectory(baseDirectory) + target;
      }
public static string AbsolutePath ( string baseDirectory , string target ) { if ( baseDirectory . Substring ( baseDirectory . Length - 1 ) == " \\ " ) { baseDirectory = baseDirectory . Substring ( 0 , baseDirectory . Length - 1 ) ; } if ( target . Substring ( 0 , 1 ) == " \\ " ) { return target ; } while ( target . IndexOf ( " \\ " ) >= 0 ) { int i = baseDirectory . LastIndexOf ( " \\ " ) ; if ( i <= 0 ) { return target ; } baseDirectory = baseDirectory . Substring ( 0 , i ) ; target = target . Substring ( 3 ) ; } return NormalizeDirectory ( baseDirectory ) + target ; }
Return absolute path from relative path
Return absolute path from relative path
// Remove last slash // Check roots // Remove up-line // Invalid Path
Returns the absolute path
Returns the absolute path
baseDirectory
string
Base (or current) directory to use when assembling absolute path
Base ( or current ) directory to use when assembling absolute path
target
string
Relative path to convert
Relative path to convert