PathHelper.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. using System.Collections.Generic;
  5. using System.IO;
  6. namespace DTHelperStd
  7. {
  8. public static class PathHelper
  9. {
  10. public static string GetFolderRelativeToProject(string testDataFolder)
  11. {
  12. List<string> finalPath = new List<string>();
  13. string startupPath = System.AppDomain.CurrentDomain.BaseDirectory;
  14. string drive = startupPath.Substring(0, startupPath.IndexOf(Path.DirectorySeparatorChar) + 1);
  15. var rootPathItems = startupPath.Split(Path.DirectorySeparatorChar);
  16. for (int i = 1; i < rootPathItems.Length - 1; i++)
  17. {
  18. if (rootPathItems[i].ToLower().Equals("bin"))
  19. {
  20. finalPath.RemoveAt(i - 2);
  21. break;
  22. }
  23. finalPath.Add(rootPathItems[i]);
  24. }
  25. var relativePathItems2 = testDataFolder.Replace('/', Path.DirectorySeparatorChar).Split(Path.DirectorySeparatorChar);
  26. foreach (var path in relativePathItems2)
  27. finalPath.Add(path);
  28. return drive + Path.Combine(finalPath.ToArray());
  29. }
  30. }
  31. }