- Home /
How can AssetDatabase.CreateFolder() possibly work?
I don't get how it can work (and consequently, I can't make it work);
I just want to create a folder, but it fails (without even throwing an error)
I don't see how anything but a toplevel folder can be made with CreateFolder (parentFolder : String, newFolderName : String)
seeing as there can be more than 1 folder with the same name in a project, how can unity possibly know which folder I mean with parentFolder ?
My guess was that waht they actually want is the path to the parent folder, but that doesn't work either.
So anyone knows how it works? bether yet, how to correctly use it?
Answer by Dave-Carlile · Jan 09, 2013 at 01:26 PM
From the documentation, the root folder appears to be the Assets folder. So if you want to create your folder directly within your Assets folder, pass "Assets" as the parent. If you want a subfolder under that, then do "Assets/My Folder".
e.g.
AssetDatabase.CreateFolder("Assets", "My Folder");
AssetDatabase.CreateFolder("Assets/My Folder", "My Sub Folder");
Edit: Corrected to use forward slashes per Bunny83, added examples
but that's what I was dooing, and it didn't work. hm, now I'm confused.
Edit: Never$$anonymous$$d, I accidently included the name of the new folder into the path of the parent folder.
anyway, Thanks, I dunno which one of you 2's answers to accept, since they're both partially right (1st one about forward slashes, 2nd one about "Assets"), so I just gave both a thumbs up
Thanks, never$$anonymous$$d, i wrote my answer on my tablet so i couldn't include much examples ;) Always tick the best answer.
Important!! make sure you dont have a trailing slash in the parent
this wont work: AssetDatabase.CreateFolder("Assets/", "$$anonymous$$y folder");
Ahhhhh thank you, you are the only one I stumbled onto who say this ! And yes, this issue is still a thing in 2020
thanks darkleptiko - I found that out the hard way and thankful for the confirmation. nice of them to mention that little nugget in the docs... :\
Answer by Bunny83 · Jan 09, 2013 at 01:21 PM
I'm pretty sure parent folder is an asset path. So it's a path with forward slashes which start in the assets folder. So just remove the first part of your path.