Exemplo n.º 1
0
        public static string AddDirectoryToDirectoryPath(string fromDirectoryPath, string toDirectoryPath)
        {
            string sFullDirectoryPath = toDirectoryPath;

            //deal with when absoluteuripath ends with a delimiter or file name
            if (Path.HasExtension(toDirectoryPath))
            {
                sFullDirectoryPath = GetDirectoryName(toDirectoryPath);
            }
            char[] cDelimiter         = FileStorageIO.GetCDelimiterForFileStorage(fromDirectoryPath);
            string sDelimiter         = FileStorageIO.GetDelimiterForFileStorage(fromDirectoryPath);
            string sLastDirectoryName = string.Empty;

            if (fromDirectoryPath.EndsWith(sDelimiter))
            {
                sLastDirectoryName = GeneralHelpers.GetSubstringFromEnd(
                    fromDirectoryPath, cDelimiter, 2);
            }
            else
            {
                sLastDirectoryName = GeneralHelpers.GetSubstringFromEnd(
                    fromDirectoryPath, cDelimiter, 1);
            }
            string sToDelimiter            = FileStorageIO.GetDelimiterForFileStorage(toDirectoryPath);
            string sLastDirectoryDelimited = string.Concat(sToDelimiter,
                                                           sLastDirectoryName, sToDelimiter);

            if (!sFullDirectoryPath.EndsWith(sLastDirectoryDelimited))
            {
                sFullDirectoryPath = Path.Combine(sFullDirectoryPath, sLastDirectoryName);
                if (!sFullDirectoryPath.EndsWith(sToDelimiter))
                {
                    sFullDirectoryPath = string.Concat(sFullDirectoryPath, sToDelimiter);
                }
            }
            return(sFullDirectoryPath);
        }