How do I get the Application Path?

I know I can get the application data path, but is it possible to get just the application path? I want to have a config file next to the executable file/icon on mac and windows and not in a folder

So I want player.exe config.dat

and for mac

Player (package) config.dat

I used this in one of my scripts:


    path = Application.dataPath;
    if (Application.platform == RuntimePlatform.OSXPlayer) {
        path += "/../../";
    }
    else if (Application.platform == RuntimePlatform.WindowsPlayer) {
        path += "/../";
    }

What I would do is `Path.GetFullPath(".")`, but didn't test it anywhere except of PC

This is a basic C# question, which applies to all apps. It’s nothing to do with Unity.

These properties were made to avoid the silly responses farting around here.

These are what you asked for:

System.AppDomain.CurrentDomain.BaseDirectory
// Exactly as it says. The Start-up directory of current application. It does not change.
// You never need to cache this as it won't change, but you sure can if you want to.
// Be sure to test this in a build. The editor play mode will give you the editor directory.

System.Environment.CurrentDirectory
// Starting value is BaseDirectory. Can be changed for complex directory operations.
// This is something you can cache several times with each change to save desired paths.

// These are the most correct answers to this question.
// There are some responses here that fart around, and others that make those look good.

I am saddened by the horrendous “answers”.

Here is code you can copy and paste into a MonoBehaviour for testing in a build.

  •   // UnityEngine built-in callback.
      void OnGUI()
      {
          string baseDir = System.AppDomain.CurrentDomain.BaseDirectory;
          string currDir = System.Environment.CurrentDirectory;
          GUI.Label(new Rect(20, 20, 1400, 20), baseDir);
          GUI.Label(new Rect(20, 40, 1400, 20), currDir);
      }
    

What I would use is Path.GetDirectoryName(Application.dataPath)

You can use Application.persistentDataPath. It’s safe to write there.

Hi, this is an old post, but this is not the solution anymore. Now the datapath leads to “nameApp_Data”, not the folder in which you have your executable.

I was looking to the solutions and here a link:
Can I get a folder up hierarchy relative to the dataPath? - Questions & Answers - Unity Discussions

So… use Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/'));
to get the Folder with the executable.

Hello,

I see that there are some ways to get the application folder path:

Application.StartupPath
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().Location)
AppDomain.CurrentDomain.BaseDirectory
System.IO.Directory.GetCurrentDirectory()
Environment.CurrentDirectory
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
System.IO.Path.GetDirectory(Application.ExecutablePath)

for more information, Please go through this link: https://stackoverflow.com/questions/6041332/best-way-to-get-application-folder-path

Thanks & Regards,
Anita

Well, if this were a regular Windows application, I would have told you to just use `Application.StartupPath`, but since it's not (and the Unity library has their own version of the Application class), I don't think what you're asking for is possible.

I'm pretty sure the `dataPath` variable is there for cross-platform compatibility, since the filesystems are different on Windows/Mac/iPhone, etc, so what the `dataPath` does is gives you a unified, safe location where you can store data, regardless of target platform.