//---------------------------------------------------------------------------
// 부모 폴더안의 모든 자식폴더 이름 얻기 (재귀 호출)
//
//
void __fastcall TForm1::GetDescendantDir(TStringList *strlstDirNames, AnsiString strPath)
{
TSearchRec sr;
try
{
if(FindFirst(strPath + "*.*", faAnyFile, sr) ==0)
{
do
{
if(sr.Name != "." && sr.Name != ".." && sr.Attr == faDirectory)
{
strlstDirNames->Add(strPath + sr.Name + "\\");
GetDescendantDir(strlstDirNames, strPath + sr.Name + "\\");
}
}
while(FindNext(sr) == 0);
}
}
__finally
{
FindClose(sr);
}
}
//---------------------------------------------------------------------------
// GetDescendantDir과 GetAllFile를 이용해서 디렉토리를 지운다.
//
//
void __fastcall TForm1::RemoveDirectory(AnsiString strPath)
{
TStringList *strlstDescPath = new TStringList;
TStringList *strlstFileName = new TStringList;
try
{
strlstDescPath->Add(strPath);
GetDescendantDir(strlstDescPath, strPath);
while(strlstDescPath->Count)
{
GetAllFile(strlstFileName, strlstDescPath->Strings[strlstDescPath->Count-1]);
while(strlstFileName->Count)
{
DeleteFile(strlstFileName->Strings[0]);
strlstFileName->Delete(0);
}
RemoveDir(strlstDescPath->Strings[strlstDescPath->Count-1]);
strlstDescPath->Delete(strlstDescPath->Count-1);
}
}
__finally
{
delete strlstDescPath;
delete strlstFileName;
}
}
//---------------------------------------------------------------------------
// 폴더안의 모든 화일이름 얻기
//
//
void __fastcall TForm1::GetAllFile(TStringList *strlstFileName, AnsiString strPath)
{
TSearchRec sr;
try
{
if(FindFirst(strPath + "*.*", faAnyFile, sr) ==0)
{
do
{
if(sr.Name != "." && sr.Name != ".." && sr.Attr != faDirectory)
strlstFileName->Add(strPath + sr.Name);
}
while(FindNext(sr) == 0);
}
}
__finally
{
FindClose(sr);
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
RemoveDirectory("D:\\20010102\\"); // 지우고자 하는 폴더를 적어준다..끝에 꼭 폴더구분기호 \\를 넣어 줘야 됩니다.
}
//---------------------------------------------------------------------------
|