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

◆ CreateFolders() [2/2]

static GUID CreateFolders ( [NotNull] Path path)
static

Creates any missing folders in the path.

Unlike AssetDatabase.CreateFolder this creates the entire path in one go rather than each folder one by one.

Path may point to either a file or folder. If the last path element has an extension it is considered a file.

Parameters
pathPath to a file or folder.
Returns
GUID of the deepest (last) folder in the path.
See also

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

255 {
256 ThrowIf.ArgumentIsNull(path, nameof(path));
257 ThrowIf.PathIsNotValid(path);
258
259 if (FileExists(path))
260 return path.FolderPath.Guid;
261
262 // if the last part has an extension we assume the path points to a file
263 var isPresumablyFilePath = String.IsNullOrEmpty(path.Extension) == false;
264 var folderPath = isPresumablyFilePath ? path.FolderPath : path;
265 if (FolderExists(folderPath))
266 return folderPath.Guid;
267
268 var folderNames = ((String)folderPath).Split(new[] { '/' });
269 var folderGuid = GuidForExistingPath(folderNames[0]); // first is "Assets"
270 var partialPath = folderNames[0];
271 for (var i = 1; i < folderNames.Length; i++)
272 {
273 partialPath += $"/{folderNames[i]}";
274 if (FolderExists(partialPath))
275 {
276 folderGuid = GuidForExistingPath(partialPath);
277 continue;
278 }
279
280 folderGuid = CreateSubFolder(Get(folderGuid), folderNames[i]);
281 }
282
283 return folderGuid;
284 }
static Boolean FolderExists([NotNull] Path path)
Tests if the given folder exists in the file system.
static Path Get([NotNull] Object asset)
Gets the relative path of an asset.
static Boolean FileExists([NotNull] Path path)
Tests if the given file exists in the file system.

References Asset.Path.FileExists(), Asset.Path.FolderExists(), and Asset.Path.Get().

+ Here is the call graph for this function: