응용 프로그램이 실행되는 실행 파일 디렉터리?
응용 프로그램이 실행되는 경로(실행 파일이 아님)를 가져와야 합니다.
System.AppDomain.CurrentDomain.BaseDirectory()
&"/images/image.jpg"로 로컬 컴퓨터에서 위 문장을 실행하면 작동이 잘 되지만 다른 컴퓨터에 응용 프로그램을 설치하면 파일을 찾을 수 없고 추가 경로 정보가 많다고 합니다.
나는 단지 앱이 실행되는 곳의 디렉토리가 필요합니다.Visual Studio 2008에서 VB.NET으로 코딩하고 있습니다.
감사합니다!
이것은 구글의 첫 번째 게시물이기 때문에 저는 사용 가능한 다른 방법과 비교 방법을 게시하려고 생각했습니다.안타깝게도 여기서 표를 만드는 방법을 알 수가 없어서 이미지입니다.각 코드는 정규화된 이름을 사용하여 이미지 아래에 있습니다.
My.Application.Info.DirectoryPath
Environment.CurrentDirectory
System.Windows.Forms.Application.StartupPath
AppDomain.CurrentDomain.BaseDirectory
System.Reflection.Assembly.GetExecutingAssembly.Location
System.Reflection.Assembly.GetExecutingAssembly.CodeBase
New System.UriBuilder(System.Reflection.Assembly.GetExecutingAssembly.CodeBase)
Path.GetDirectoryName(Uri.UnescapeDataString((New System.UriBuilder(System.Reflection.Assembly.GetExecutingAssembly.CodeBase).Path)))
Uri.UnescapeDataString((New System.UriBuilder(System.Reflection.Assembly.GetExecutingAssembly.CodeBase).Path))
2021년 10월 18일 편집:
sheak... net5.0 또는 net6.0을 사용하고 앱을 단일 파일 번들로 게시하는 경우 위의 작업은 수행되지 않습니다.지금 내가 가진 최선은:
// This will give you the directory but not the assembly
string basedir = AppContext.BaseDirectory;
// Before you package the app as a single file bundle, you will get the dll.
// But after you publish it, you'll get the exe.
string pathToExecutable = Environment.GetCommandLineArgs()[0].Replace(".dll", ".exe");
Dim strPath As String = System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
실행 방법: 실행 중인 응용 프로그램 경로(MSDN) 결정
저는 이것을 알아야 했고 환경 수업을 기억하기 전에 여기에 왔습니다.
다른 사용자가 이 문제를 일으킨 경우 다음을 사용하십시오.Environment.CurrentDirectory
.
예:
Dim dataDirectory As String = String.Format("{0}\Data\", Environment.CurrentDirectory)
Visual Studio에서 디버그 모드 수율로 실행하는 경우:
C:\Development\solution folder\application folder\bin\debug
이것은 제가 필요로 했던 정확한 행동이고, 충분히 간단하고 간단합니다.
Dim P As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
P = New Uri(P).LocalPath
응용 프로그램 클래스의 정적 StartupPath 속성을 사용할 수 있습니다.
다음을 작성할 수 있습니다.
Path.Combine(Path.GetParentDirectory(GetType(MyClass).Assembly.Location), "Images\image.jpg")
언급URL : https://stackoverflow.com/questions/2593458/executable-directory-where-application-is-running-from
'code' 카테고리의 다른 글
몽구스 프로미스 사용법 - 몽고 (0) | 2023.05.23 |
---|---|
Git의 디렉터리에 있는 파일을 어떻게 무시합니까? (0) | 2023.05.23 |
VB.NET 및 C#의 값에 대해 null을 확인하는 데 차이가 있는 이유는 무엇입니까? (0) | 2023.05.18 |
Excel 시트를 데이터 테이블로 읽는 가장 좋은/가장 빠른 방법은 무엇입니까? (0) | 2023.05.18 |
strings.xml의 다른 문자열에서 한 문자열을 참조하시겠습니까? (0) | 2023.05.18 |