ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [C#] 현재 실행 파일 이름 및 경로 얻어오기 방법
    개발 2019. 12. 30. 16:23
    반응형

    Log 파일을 저장하거나 Data 파일을 Export 해야 하는 경우

    현재 애플리케이션 파일 실행 폴더 밑에 폴더를 생성하거나 실행 파일명 이름을

    이용하는 경우가 있습니다

    이때, 실행 파일 이름 및 파일 경로를 얻어오는 방법은 아래처럼 여러 가지가 있습니다

           private void DisplayExcutingFileNameAndPath()
            {
                Console.WriteLine("Application.ProductName : {0}", Application.ProductName);
                Console.WriteLine("Application.StartupPath : {0}", Application.StartupPath);
                Console.WriteLine("Application.ExecutablePath : {0}", Application.ExecutablePath);
                Console.WriteLine();
                Console.WriteLine("System.AppDomain.CurrentDomain.FriendlyName : {0}", System.AppDomain.CurrentDomain.FriendlyName);
                Console.WriteLine("System.Diagnostics.Process.GetCurrentProcess().ProcessName : {0}", System.Diagnostics.Process.GetCurrentProcess().ProcessName);
                Console.WriteLine("System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName : {0}", System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
                Console.WriteLine();
                Console.WriteLine("System.IO.Path.GetFileName() : {0}", System.IO.Path.GetFileName(Application.ExecutablePath));
                Console.WriteLine("System.IO.Path.GetFileNameWithoutExtension() : {0}", System.IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath));
                Console.WriteLine("System.IO.Path.GetFileName() : {0}", System.IO.Path.GetFileName(Application.ExecutablePath));
                Console.WriteLine();
                Console.WriteLine("System.Reflection.Assembly.GetEntryAssembly() : {0}", System.Reflection.Assembly.GetEntryAssembly());
                Console.WriteLine("System.Reflection.Assembly.GetEntryAssembly().Location : {0}", System.Reflection.Assembly.GetEntryAssembly().Location);
                Console.WriteLine("System.Reflection.Assembly.GetEntryAssembly().FullName : {0}", System.Reflection.Assembly.GetEntryAssembly().FullName);
                Console.WriteLine("System.Reflection.Assembly.GetEntryAssembly().GetName() : {0}", System.Reflection.Assembly.GetEntryAssembly().GetName());
                Console.WriteLine("System.Reflection.Assembly.GetEntryAssembly().GetName().Name : {0}", System.Reflection.Assembly.GetEntryAssembly().GetName().Name);
                Console.WriteLine();
                Console.WriteLine("System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name : {0}", System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name);
                Console.WriteLine("System.Reflection.Assembly.GetEntryAssembly().ManifestModule.FullyQualifiedName : {0}", System.Reflection.Assembly.GetEntryAssembly().ManifestModule.FullyQualifiedName);
                Console.WriteLine("System.Reflection.Assembly.GetEntryAssembly().ManifestModule.ScopeName : {0}", System.Reflection.Assembly.GetEntryAssembly().ManifestModule.ScopeName);
                Console.WriteLine();
                Console.WriteLine("System.Reflection.Assembly.GetExecutingAssembly() : {0}", System.Reflection.Assembly.GetExecutingAssembly());
                Console.WriteLine("System.Reflection.Assembly.GetExecutingAssembly().Location : {0}", System.Reflection.Assembly.GetExecutingAssembly().Location);
                Console.WriteLine("System.Reflection.Assembly.GetExecutingAssembly().FullName : {0}", System.Reflection.Assembly.GetExecutingAssembly().FullName);
                Console.WriteLine("System.Reflection.Assembly.GetExecutingAssembly().GetName() : {0}", System.Reflection.Assembly.GetExecutingAssembly().GetName());
                Console.WriteLine("System.Reflection.Assembly.GetExecutingAssembly().GetName().Name : {0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
                Console.WriteLine();
                Console.WriteLine("System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name : {0}", System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name);
                Console.WriteLine("System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName : {0}", System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
                Console.WriteLine("System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.ScopeName : {0}", System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.ScopeName);
            }

     

    실행 결과 값

    Application.ProductName : DevTestApp
    Application.StartupPath : C:\Users\banana\source\repos\DevTestApp\DevTestApp\bin\Debug
    Application.ExecutablePath : C:\Users\banana\source\repos\DevTestApp\DevTestApp\bin\Debug\DevTestApp.exe

    System.AppDomain.CurrentDomain.FriendlyName : DevTestApp.exe
    System.Diagnostics.Process.GetCurrentProcess().ProcessName : DevTestApp
    System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName : C:\Users\banana\source\repos\DevTestApp\DevTestApp\bin\Debug\DevTestApp.exe

    System.IO.Path.GetFileName() : DevTestApp.exe
    System.IO.Path.GetFileNameWithoutExtension() : DevTestApp
    System.IO.Path.GetFileName() : DevTestApp.exe

    System.Reflection.Assembly.GetEntryAssembly() : DevTestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
    System.Reflection.Assembly.GetEntryAssembly().Location : C:\Users\banana\source\repos\DevTestApp\DevTestApp\bin\Debug\DevTestApp.exe
    System.Reflection.Assembly.GetEntryAssembly().FullName : DevTestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
    System.Reflection.Assembly.GetEntryAssembly().GetName() : DevTestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
    System.Reflection.Assembly.GetEntryAssembly().GetName().Name : DevTestApp

    System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name : DevTestApp.exe
    System.Reflection.Assembly.GetEntryAssembly().ManifestModule.FullyQualifiedName : C:\Users\banana\source\repos\DevTestApp\DevTestApp\bin\Debug\DevTestApp.exe
    System.Reflection.Assembly.GetEntryAssembly().ManifestModule.ScopeName : DevTestApp.exe

    System.Reflection.Assembly.GetExecutingAssembly() : DevTestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
    System.Reflection.Assembly.GetExecutingAssembly().Location : C:\Users\banana\source\repos\DevTestApp\DevTestApp\bin\Debug\DevTestApp.exe
    System.Reflection.Assembly.GetExecutingAssembly().FullName : DevTestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
    System.Reflection.Assembly.GetExecutingAssembly().GetName() : DevTestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
    System.Reflection.Assembly.GetExecutingAssembly().GetName().Name : DevTestApp

     

     

     

    반응형

    댓글

Designed by Tistory.