CodeSmile AssetDatabase 1.9
Unity's AssetDatabase in enjoyable, consistent, concise, convenient, comprehensible, safe, documented form.
Loading...
Searching...
No Matches

◆ IsValid()

static Boolean IsValid ( [NotNull] String path)
static

Returns true if the provided path is valid.

If this returns false CodeSmileEditor.Asset.GetLastErrorMessage contains the error message.

Parameters
pathString representation of an absolute or relative path.
Returns
True if the string is a valid path and contains no illegal characters for a path or file, and isn't too long. False in all other cases.
See also

Definition at line 194 of file Asset.Path.Static.cs.

195 {
196 var isValid = true;
197
198 try
199 {
200 // System.IO will throw for most illegal chars, plus some extra checks
201 var fileName = System.IO.Path.GetFileName(path);
202 var folderName = System.IO.Path.GetDirectoryName(path);
203
204 // check folder name for some chars that System.IO allows in GetDirectoryName
205 var testIllegalChars = new Func<Char, Boolean>(c => c == '*' || c == '?' || c == ':');
206 isValid = folderName.Any(testIllegalChars) == false;
207
208 if (isValid)
209 {
210 // check filename for some chars that System.IO allows in GetFileName
211 fileName = path.Substring(folderName.Length, path.Length - folderName.Length);
212 isValid = fileName.Any(testIllegalChars) == false;
213 }
214 }
215 catch (Exception ex)
216 {
217 SetLastErrorMessage($"{ex.Message} => \"{path}\"");
218 isValid = false;
219 }
220
221 return isValid;
222 }