2013-08-14 3 views
1

D : 드라이브에 저장된 vb.net 응용 프로그램이 있습니다. 프로젝트 루트 디렉토리에 폴더와 파일을 만들어야합니다. 나는 다음의 코드를 사용하여 폴더와 파일을 생성했다.내 프로젝트 루트 디렉토리에 폴더 및 파일을 만드는 방법

If (Not System.IO.Directory.Exists("\test\")) Then 
       System.IO.Directory.CreateDirectory("\test\") 
       If (Not System.IO.File.Exists("\test\output.txt")) Then 
        System.IO.File.Create("\test\output.txt") 
       End If 
      End If 

그러나 폴더와 파일은 C : 드라이브에 생성됩니다. Dim fullpath As String = Path.GetFullPath("\test\output.txt")을 사용하여 파일 및 폴더의 생성 위치를 식별했습니다.

내 프로젝트 루트 디렉토리에 만들고 싶습니다. 즉 상대 경로 기준을 사용하여 폴더를 만들어야합니다.

+0

답변이 도움이 되었습니까? – SoftwareCarpenter

답변

2

당신은 실행중인 응용 프로그램의 실행 파일이나 DLL의 디렉토리를 원하는 경우 :

Dim spath As String 
     spath = System.IO.Path.GetDirectoryName(_ 
        System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) 
     If (Not System.IO.Directory.Exists(Path.Combine(spath, "test"))) Then 

      System.IO.Directory.CreateDirectory(Path.Combine(spath, "test")) 

      If (Not System.IO.File.Exists(Path.Combine(spath, "test\output.txt"))) Then 

       System.IO.File.Create(Path.Combine(spath, "test\output.txt")) 
      End If 
     End If 

당신은 다음 솔루션/프로젝트 디렉토리하려면 다음


 Dim spath As String = Directory.GetCurrentDirectory 

     If (Not System.IO.Directory.Exists(Path.Combine(spath, "test"))) Then 
      System.IO.Directory.CreateDirectory(Path.Combine(spath, "test")) 
      If (Not System.IO.File.Exists(Path.Combine(spath, "test\output.txt"))) Then 
       System.IO.File.Create(Path.Combine(spath, "test\output.txt")) 
      End If 
     End If 
0

당신은 사용할 수를 이 길은 그곳에서 일합니다. ...

MsgBox(Application.StartupPath) 
관련 문제