- Home /
Directory.CreateDirectory not working
es, exactly that. I try it with the proper syntax, and it doesn't create the folder. Here's my code:
Directory.CreateDirectory("~/Library/Application Support/PROJECT_TITLE");
I should see a new folder appear in ~/Library/Application Support
called PROJECT_TITLE
, right? I run it and trigger the function, and no errors pop up. Then I check in Finder, and the folder is not there!
EDIT:
Okay, so it turned out it was just putting all of those folders within the project folder itself. How can I make it so it does it from the root folder?
Answer by SkaredCreations · Oct 19, 2018 at 03:17 PM
You can try to use System.Environment.GetFolderPath to get your user's personal folder (that corresponds to "~/") and then use System.IO.Path.Combine to combine it with the rest of path:
string homeRoot = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
string newFolder = System.IO.Path.Combine(homeRoot, "Library/Application Support/PROJECT_TITLE");
System.IO.Directory.CreateDirectory(newFolder);
You can find more options of System.Environment.GetFolderPath at here.
Your answer
Follow this Question
Related Questions
EditorUtility.OpenFilePanel uses \ FileInfo.Name uses / 0 Answers
Can't Create Directory 1 Answer
Importing files from a path via C# script 0 Answers