2017-05-08 2 views
0

내 .exe 파일이에되는 상위 폴더에서 .EXE 파일을 시작하려고로 변환 할 수없는 불행하게도값은 '문자열'

할 때 :.

dir = Directory.GetParent(Directory.GetCurrentDirectory)) 

Value type of 'DirectoryInfo' cannot be converted to 'String'.

그것은 CurrentDirectory 완벽하게 작동하지만 GetParent하지 않습니다 :

이 프로그램은 나에게 오류를 제공합니다. 난 그냥 두지 경우에도 :

dir = Directory.GetParent("") 

나는 그들이 모두 동일한 파일 형식을 반환하지만합니다 (GetParent 방법을 통해 음영 경우) 비주얼 스튜디오는 GetParentDirectoryInfo 값을 반환 하더군요 생각합니다.

문자열로 변환하거나 내 필요에 사용할 수있는 방법이 있습니까?

답변

0

Directory.GetParentDirectoryInfo 클래스를 반환하고 오류가 말한대로이 문자열로 변환 할 수 없습니다. 물론

Dim dirInfo As DirectoryInfo = Directory.GetParent(Directory.GetCurrentDirectory) 
Dim path As String = dirInfo.FullName 

이것은 하나의 라이너하지만 위해 수행 할 수 있습니다

:

대신 싶은 것은 구체적에서 속성에 액세스 한 후 DirectoryInfo를 개최 할 수있는 변수를 선언 FullName 속성입니다 clarification 나는 그것을 깨뜨리는 데 도움이 될 것이라고 생각했다. 하나의 라이너에 이용 :

Dim dir As String = Directory.GetParent(Directory.GetCurrentDirectory).FullName 

두 경우의 출력은 :

C:\Development\VS2013\WindowsApplication1\bin