12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- namespace textUtility
- {
- using System;
- using System.Collections.Generic;
- using System.IO;
-
- using UnityEngine;
-
- public static class PathExtension
- {
- public static string GetRelativePath(this string path)
- {
- return "Assets" + path.Replace(Application.dataPath, "");
- }
-
- public static List<string> GetAllFileNameFromPath(this List<string> pathes)
- {
- List<string> fileName = new List<string>();
- foreach (var path in pathes)
- {
- fileName.Add(Path.GetFileName(path));
- }
- return fileName;
- }
-
- 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 = string.Format("{0}{1}{2}{3}", directory, Path.DirectorySeparatorChar, name, extension);
- while (File.Exists(newFileName))
- {
- newFileName = string.Format("{0}{1}{2} ({3}){4}", 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 = string.Format("{0} ({1})", directoryName, count++);
- }
- return newDirectoryName;
- }
- }
- }
|