ExPath.cs 778 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. namespace labelUtility
  2. {
  3. using System.IO;
  4. using UnityEngine;
  5. public static class ExPath
  6. {
  7. public static string GetRelativePath(this string path)
  8. {
  9. return "Assets" + path.Replace(Application.dataPath, "");
  10. }
  11. public static string GetUnRepeatFileName(this string fileName)
  12. {
  13. string extension = Path.GetExtension(fileName);
  14. string directory = Path.GetDirectoryName(fileName);
  15. string name = Path.GetFileNameWithoutExtension(fileName);
  16. int count = 0;
  17. string newFileName = $"{directory}/{name}{extension}";
  18. while (File.Exists(newFileName))
  19. {
  20. count++;
  21. newFileName = $"{directory}/{name} ({count}){extension}";
  22. }
  23. return newFileName;
  24. }
  25. }
  26. }