So I am currently working using a Unity project in a specific repository. How can I get the name of this repository I am working in? That is, the name of the folder directly above the .git folder.
The way I have done it is like so:
Directory.GetCurrentDirectory().GetParentDirectory().GetParentDirectory().GetParentDirectory().GetFilename();
However, this feels like not the best way to do it since it's almost like as if I am hard coding?
What other ways can I do this?
CodePudding user response:
You could probably start with a known folder like e.g. Application.dataPath
which is the Assets
folder and from there bubble up until you find the root
var directory = new DirectoryInfo(Application.dataPath);
while(directory.GetDirectories(".git").Length == 0)
{
directory = directory.Parent;
}
var repositoryPath = directory.FullName;
var repositoryName = Path.GetFileName(repositoryPath);
CodePudding user response:
Assuming you mean the folder of your code when you run your game:
You can use AppDomain.CurrentDomain.BaseDirectory
as stated in this question