2using System.Collections;
3using System.Collections.Generic;
5using System.Text.RegularExpressions;
12 public static class pb_FileUtility
17 public static string ReadFile(
string path)
19 if( !
File.Exists(path))
21 Debug.LogError(
"File path does not exist!\n" + path);
25 string contents =
File.ReadAllText(path);
33 public static bool SaveFile(
string path,
string contents)
37 File.WriteAllText(path, contents);
39 catch(System.Exception e)
41 Debug.LogError(
"Failed writing to path: " + path +
"\n" + e.ToString());
48 public static bool IsValidPath(
string path,
string extension)
50 return !
string.IsNullOrEmpty(path) &&
51 Directory.Exists(path.Remove(path.LastIndexOf(
"/"))) &&
52 path.EndsWith(extension);
56 public static bool IsValidPath(
string path)
58 return !
string.IsNullOrEmpty(path) &&
59 Directory.Exists(path.Remove(path.LastIndexOf(
"/")));
66 public static string GetFullPath(
string path)
68 string full = Path.GetFullPath(path);
75 public static PathType GetPathType(
string path)
83 public static string SanitizePath(
string path,
string extension =
null)
85 string rep = GetFullPath(path);
88 rep = Regex.Replace(rep,
"(\\\\|\\\\\\\\){1,2}|(/)",
"/");
92 if(extension !=
null && !rep.EndsWith(extension))
94 if(!extension.StartsWith(
"."))
95 extension =
"." + extension;