遍历目录下所有文件

void __fastcall GetFiles(AnsiString Dir)
{
    TSearchRec sr;
    TStringList *FileList=new TStringList(); //保存文件名的List
    if (FindFirst( Dir+"*.*",faAnyFile,sr) == 0)
    {
        try {
            do{
                if (sr.Name=="." || sr.Name=="..")
                    continue;
                if ((sr.Attr & faDirectory) != 0) {
                    //找到一个目录
                    //不嵌套查詢,如果要嵌套查詢,去掉 continue 和註釋即可
                    //GetFiles(Dir+sr.Name + "\\
"); //递归调用
                    continue;
                }
                else {
                    FileList->Add(sr.Name);
                }
            }while (FindNext(sr) == 0);
            FindClose(sr);
        }
        catch(...) {            
            FindClose(sr);
        }
    }
}

你可能感兴趣的:(list)