ExPath.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. namespace deleteUtility
  3. {
  4. using System.IO;
  5. using UnityEngine;
  6. public static class ExPath
  7. {
  8. public static string GetRelativePath(this string path)
  9. {
  10. return "Assets" + path.Replace(Application.dataPath, "");
  11. }
  12. public static string GetUnRepeatFileName(this string fileName)
  13. {
  14. string extension = Path.GetExtension(fileName);
  15. string directory = Path.GetDirectoryName(fileName);
  16. string name = Path.GetFileNameWithoutExtension(fileName);
  17. int count = 1;
  18. string newFileName = string.Format("{0}{1}{2}{3}", directory, Path.DirectorySeparatorChar, name, extension);
  19. while (File.Exists(newFileName))
  20. {
  21. newFileName = string.Format("{0}{1}{2} ({3}){4}", directory, Path.DirectorySeparatorChar, name, count++, extension);
  22. }
  23. return newFileName;
  24. }
  25. public static string GetUnRepeatDirectoryName(this string directoryName)
  26. {
  27. int count = 1;
  28. string newDirectoryName = directoryName;
  29. while (Directory.Exists(newDirectoryName))
  30. {
  31. newDirectoryName = string.Format("{0} ({1})", directoryName, count++);
  32. }
  33. return newDirectoryName;
  34. }
  35. }
  36. }