- Home /
Path.GetDirectoryName returns "null" in build
Hey guys, I´m trying to get the name of a Directory to be stored in a string called "pathtemp", below is the relevant part of my code. This works like a charm in the editor, no problems there. But in a standalone build - the same code returns null. Does anyone have an idea about what is going wrong?
FileInfo[] info;
DirectoryInfo di = new DirectoryInfo (Application.dataPath);
info = di.GetFiles ("*.*");
foreach (FileInfo filename in info) {
string filename_string;
filename_string = filename.ToString ();
pathtemp = Path.GetDirectoryName (filename_string);
}
Answer by MaxGuernseyIII · Jan 05, 2018 at 08:49 PM
All the pathing stuff is a lot less smart than you would want it to be. Try getting the absolute path (with Path.GetFullPath), first, then getting the directory name off the absolute path.
Thanks $$anonymous$$ate, though this doesn´t cut it either. Seems like GetDirectoryName as well as GetFullPath produce different results, depending on wether you are running in the editor or as a standalone build. $$anonymous$$ighty strange. The only thing offering consistent outcomes (no matter if in-editor or standalone) seems to be FileInfo.FullName. If anyone was wondering.
Your answer
![](https://koobas.hobune.stream/wayback/20220612145916im_/https://answers.unity.com/themes/thub/images/avi.jpg)