1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- namespace deleteUtility
- {
- using System.IO;
- using UnityEngine;
- public static class ExPath
- {
- public static string GetRelativePath(this string path)
- {
- return "Assets" + path.Replace(Application.dataPath, "");
- }
- public static string GetUnRepeatFileName(this string fileName)
- {
- string extension = Path.GetExtension(fileName);
- string directory = Path.GetDirectoryName(fileName);
- string name = Path.GetFileNameWithoutExtension(fileName);
- int count = 1;
- string newFileName = $"{directory}{Path.DirectorySeparatorChar}{name}{extension}";
- while (File.Exists(newFileName))
- {
- newFileName = $"{directory}{Path.DirectorySeparatorChar}{name} ({count++}){extension}";
- }
- return newFileName;
- }
- public static string GetUnRepeatDirectoryName(this string directoryName)
- {
- int count = 1;
- string newDirectoryName = directoryName;
- while (Directory.Exists(newDirectoryName))
- {
- newDirectoryName = $"{directoryName} ({count++})";
- }
- return newDirectoryName;
- }
- }
- }
|