본문 바로가기

Language/C#

Directoy내 특정 파일 검색

루프를 두번 돌릴 필요 없이 가능하다.
C#의 장점이라고 해야하나?ㅎㅎㅎㅎ
원하는 File의 Path를 받아오는 방법이다.

using System.IO
//Directoy 클레스를 사용하기 위함이다.

private string []ImageFilePath;
//찾고자 하는 파일들의 경로를 받아온다. 전역(멤버)로 선언.

string []SerachFiles = Directoy.GetFiles(FilePath ,"*.jpg");
//FilePath 경로의 디렉토리에 "*.jpg" 만 검사하여 가지고 온다.

ImageFilePath = new string[SearchFiles.Count()];
//SearchFiles의 배열의 크기만큼 메모리 할당.
int i;
foreach(string files in SearchFiles)
{
            ImageFilePath[i] = fils;
            i++;
}

for문을 써도 관계없다...음...원래 있던 코드에다가 해서 foreach를 걍 썼는데 쓸때 없이 메모리가 낭비된다. for문으로 변경..ㅡㅡㅋ
for(int i = 0; i < SearchFiles.Count(); i++)
{
            ImageFilePath[i] = fils[i];
}

머...자기 나름?ㅋㅋㅋㅋ