2014-01-08 4 views
0

예를 들어 프로젝트 디렉토리에서 파일 수를 얻고 싶으면. Java에서 나는 작성합니다프로젝트 디렉토리의 경로를 얻는 방법

int numberOfFiles = new File(".").listFiles().length; 

하지만 .NET에서 프로젝트의 디렉토리 경로를 얻는 방법을 모르겠어요. 어떻게 C#에서 동일한 목표를 달성하기 위해?

+0

가능한 중복 : http://stackoverflow.com/questions/1658518/getting-the-absolute-path-of-the-executable- 디렉터리가 있으면, 파일 수를 쉽게 얻을 using-c – Pedrom

답변

2

가까이

var path = Path.GetDirectoryName(Application.ExecutablePath); 
var files = Directory.GetFiles(path); 
1

간단합니다 - 사용 :

int numberOfFiles = Directory.GetFiles(".").Length 
+0

John Koerner 솔루션과 비교하여 (결과, 효과) 차이가 있습니까? – Yoda

+1

_result_는 동일해야합니다. _performance_가 다른지 확인하려면 두 가지 방법을 시도해야합니다. –

+0

당신은 어느 것을 선호합니까? 참조 솔루션 -> 순수 주의자의 솔루션을 알고 싶습니다. – Yoda

1

당신은 Application.ExecutablePath를 사용하여 실행 파일의 경로를 가져온 다음 거기에서 디렉토리를 얻을 수 있습니다.

var executingDir = System.IO.Path.GetDirectoryName(Application.ExecutablePath); 
var numFiles = System.IO.Directory.GetFiles(executingDir).Count(); 
Console.WriteLine(numFiles); 
관련 문제