가끔 긁어 쓸 일이 있는 디렉토리내 파일 및 폴더 리스트 얻기입니다.
#include <vcl.h>
#pragma hdrstop
#include <FileCtrl.hpp>
//---------------------------------------------------------------------------
// 지정한 폴더 및 하위 폴더에 대해 모든 파일명을 다 가져온다.
// strPath 는 ....\\ 형태이어야 한다.
void CMain::GetDirFileName(TStringList *strlstDirNames, String strPath)
{
TSearchRec sr;
try
{
if(FindFirst(strPath + "*.*", faAnyFile, sr) ==0)
{
do
{
// 디렉토리이면 재귀호출
if(sr.Name != "." && sr.Name != ".." && (sr.Attr & faDirectory))
{
GetDirFileName(strlstDirNames, strPath + sr.Name + "\\");
}
else
strlstDirNames->AddObject(strPath + sr.Name, (TObject*) sr.Size);
} while(FindNext(sr) == 0);
}
}
__finally
{
FindClose(sr);
}
}
void GetDirs_And_FileName(TStringList *strlstDirNames, String strPath)
{
TSearchRec sr;
try
{
if (FindFirst(strPath + "\\*.*", faAnyFile, sr) ==0)
{
do
{
// 디렉토리이면 재귀호출
if (sr.Name != "." && sr.Name != ".." && (sr.Attr & faDirectory))
{
strlstDirNames->AddObject(strPath + "\\" + sr.Name, (TObject*) 0); // 0은 디렉토리표시.
GetDirs_FileName(strlstDirNames, strPath + "\\" + sr.Name);
}
else if (sr.Name != "." && sr.Name != ".." && sr.Size > 1)
strlstDirNames->AddObject(strPath + "\\" + sr.Name, (TObject*) sr.Size);
} while(FindNext(sr) == 0);
}
}
__finally
{
FindClose(sr);
}
}
// 디렉토리 리스트만 얻는다.
void CMain::GetDirs(TStringList *strlstDirNames, String strPath)
{
TSearchRec sr;
try
{
if(FindFirst(strPath + "*.*", faAnyFile, sr) ==0)
{
do
{
// 디렉토리이면 재귀호출
if(sr.Name != "." && sr.Name != ".." && (sr.Attr & faDirectory))
{
strlstDirNames->AddObject(strPath + sr.Name + "\\", (TObject*) sr.Size);
GetDirFileName(strlstDirNames, strPath + sr.Name + "\\");
}
} while(FindNext(sr) == 0);
}
}
__finally
{
FindClose(sr);
}
}
//---------------------------------------------------------------------------
// 폴더를 선택 한다..
bool CMain::SelectFolder(HWND Handle, char* Folder)
{
String dir = Folder;
if (SelectDirectory("작업을 원하는 폴더를 선택하세요. ^^", "", dir))
{
strcpy(Folder, dir.c_str());
return true;
}
return false;
}
//---------------------------------------------------------------------------
|