Exemplo n.º 1
0
        /// <summary>
        /// Get the file path part of a path which starts after end of RootPath.
        /// </summary>
        /// <param name="InFullPath"></param>
        /// <param name="InRootPath"></param>
        /// <returns></returns>
        public static string GetFilePath(string InFullPath, string InRootPath)
        {
            // todo: extract the first slash char used in the paths.  Then make sure all
            //       the slash chars are that char.

            // simplify the comparison by making sure both paths use the same slash char.
            string fullPath = InFullPath.ReplaceAll('/', '\\');
            string rootPath = InRootPath.ReplaceAll('/', '\\');

            // if one of the paths starts with root slash, make sure the other does also.
            if ((fullPath.Length > 0) && (rootPath.Length > 0))
            {
                int fx1 = Scanner.ScanNotEqual(rootPath, 0, '\\').ResultPos;
                int fx2 = Scanner.ScanNotEqual(fullPath, 0, '\\').ResultPos;
                if ((fx1 == -1) && (fx2 != -1))
                {
                    rootPath = '\\' + rootPath;
                }
                else if ((fx1 != -1) && (fx2 == -1))
                {
                    fullPath = '\\' + fullPath;
                }
            }

            string filePath = "";

            while (true)
            {
                // leave loop when the remaining rootPath is the RootPath to crack on.
                if (fullPath == rootPath)
                {
                    break;
                }

                // crack dirPath on the last "/".
                string s1 = Pather.GetDirectoryName(fullPath);
                string s2 = Pather.GetFileName(fullPath);

                // accumulate to the cracked right side path.
                if (filePath.Length == 0)
                {
                    filePath = s2;
                }
                else
                {
                    filePath = Path.Combine(s2, filePath);
                }

                fullPath = s1;
            }

            return(filePath);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Crack path on its head, the root dir in the path.
        /// ( a path w/o a slash returns rootDir as an empty string )
        /// This is effectively the opposite of GetFileName and GetDirectoryName.
        /// Another name for this method would be "GetRootDirectory" and
        /// "GetScopePath".
        /// </summary>
        /// <param name="InPath"></param>
        /// <returns></returns>
        public static string[] Head(string InPath)
        {
            string path    = InPath;
            string rootDir = "";
            string remPath = "";

            // loop cracking names off the right side of the path until
            // a simple name remains.
            while (true)
            {
                string s1 = null;
                string s2 = null;

                if (path.Length == 0)
                {
                    s1 = "";
                    s2 = "";
                }
                else
                {
                    s1 = Pather.GetDirectoryName(path);
                    s2 = Pather.GetFileName(path);
                }

                // simple name from left side of path remains. This is the root
                // dir of the path.
                if (s1.Length == 0)
                {
                    rootDir = path;
                    break;
                }

                else
                {
                    remPath = Path.Combine(s2, remPath);
                    path    = s1;
                }
            }

            return(new string[] { rootDir, remPath });
        }
Exemplo n.º 3
0
        public RootPath GetRootPath(ScopePath InScopePath)
        {
            string rootPath = Pather.GetRootPath(mFullPath, InScopePath.ToString());

            return(new RootPath(rootPath));
        }