ServerPathUtils.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using Utilities;
  11. namespace SMBLibrary.Server
  12. {
  13. public class ServerPathUtils
  14. {
  15. /// <param name="path">UNC path, e.g. '\\192.168.1.1\Shared'</param>
  16. /// <returns>e.g. \Shared</returns>
  17. public static string GetRelativeServerPath(string path)
  18. {
  19. if (path.StartsWith(@"\\"))
  20. {
  21. int index = path.IndexOf('\\', 2);
  22. if (index > 0)
  23. {
  24. return path.Substring(index);
  25. }
  26. else
  27. {
  28. return String.Empty;
  29. }
  30. }
  31. return path;
  32. }
  33. /// <param name="path">UNC path, e.g. '\\192.168.1.1\Shared\*'</param>
  34. /// <returns>e.g. \*</returns>
  35. public static string GetRelativeSharePath(string path)
  36. {
  37. if (path.StartsWith(@"\\"))
  38. {
  39. int firstIndex = path.IndexOf('\\', 2);
  40. int index = path.IndexOf('\\', firstIndex + 1);
  41. if (index > 0)
  42. {
  43. return path.Substring(index);
  44. }
  45. else
  46. {
  47. return path;
  48. }
  49. }
  50. return path;
  51. }
  52. }
  53. }