ExPath.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. namespace deleteUtility
  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 = 1;
  17. string newFileName = $"{directory}{Path.DirectorySeparatorChar}{name}{extension}";
  18. while (File.Exists(newFileName))
  19. {
  20. newFileName = $"{directory}{Path.DirectorySeparatorChar}{name} ({count++}){extension}";
  21. }
  22. return newFileName;
  23. }
  24. public static string GetUnRepeatDirectoryName(this string directoryName)
  25. {
  26. int count = 1;
  27. string newDirectoryName = directoryName;
  28. while (Directory.Exists(newDirectoryName))
  29. {
  30. newDirectoryName = $"{directoryName} ({count++})";
  31. }
  32. return newDirectoryName;
  33. }
  34. }
  35. }