Posts C# - 스크립트(.cs), 어셈블리(.dll, .exe) 경로 참조
Post
Cancel

C# - 스크립트(.cs), 어셈블리(.dll, .exe) 경로 참조

스크립트 경로

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static void GetScriptPath([System.Runtime.CompilerServices.CallerFilePath] string filePath = "")
{
    // 1. Script(.cs) Path
    _ = filePath;

    // 2. Folder Path
    string folderPath = System.IO.Path.GetDirectoryName(filePath);

    // 3. Specific Root Folder Path
    string rootFolderName = @"Assets\";
    int rootIndex = folderPath.IndexOf(rootFolderName);
    if (rootIndex > -1)
    {
        string rootFolderPath = folderPath.Substring(rootIndex, folderPath.Length - rootIndex);
    }
}


어셈블리 경로

1
2
3
4
5
string filePath =
    System.Reflection.Assembly.GetExecutingAssembly().Location;

string folderPath = 
    System.IO.Path.GetDirectoryName(filePath);
This post is licensed under CC BY 4.0 by the author.