ExPath.cs 842 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. namespace labelUtility
  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 = 0;
  18. string newFileName = string.Format("{0}/{1}{2}", directory, name, extension);
  19. while (File.Exists(newFileName))
  20. {
  21. count++;
  22. newFileName = string.Format("{0}/{1} ({2}){3}", directory, name, count, extension);
  23. }
  24. return newFileName;
  25. }
  26. }
  27. }