-
[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반응형'개발' 카테고리의 다른 글
포토샵 CS3 메뉴 크기 고해상도 화면에서 변경하기 (0) 2021.01.08 [C#] Excel 엑셀 파일 생성 시 예외 오류 처리 0x80010105 RPC_E_SERVERFAULT (0) 2020.10.05 [C# 코딩] DevExpress GridControl 사용하여 개발하기 - 기본 (0) 2019.08.24 [C#] 프로그램 파일 실행 경로, 파일 이름, 파일 버전 얻어 오기 (0) 2019.08.21 비주얼 스튜디오 커뮤니티 라이센스 만료 시 해결 방법 및 Visual Studio Community 다운로드 설치 (0) 2019.08.14