|
빌더에서 FindFirst 치고 F1을 눌러봤습니다. --;
Example까지 있네요..
------------------------------------------------------
Searches for the first instance of a file name with a given set of attributes in a specified directory.
Unit
Sysutils
Category
file management routines
extern PACKAGE int __fastcall FindFirst(const AnsiString Path, int Attr, TSearchRec &F);
Description
FindFirst searches the directory specified by Path for the first file that matches the file name implied by Path and the attributes specified by the Attr parameter. The result is returned in the F parameter. Use the fields of this search record to extract the information needed. FindFirst returns 0 if a file was successfully located, otherwise, it returns a Windows error code.
The Path constant parameter is the directory and file name mask, including wildcard characters. For example, 밹:\test\*.*
?specifies all files in the C:\TEST directory).
The Attr parameter specifies the special files to include in addition to all normal files. Choose from these file attribute constants when specifying the Attr parameter:
Constant Value Description
faReadOnly $00000001 Read-only files
faHidden $00000002 Hidden files
faSysFile $00000004 System files
faVolumeID $00000008 Volume ID files
faDirectory $00000010 Directory files
faArchive $00000020 Archive files
faAnyFile $0000003F Any file
Attributes can be combined by or-ing their constants or values. For example, to search for read-only and hidden files in addition to normal files, pass (faReadOnly | faHidden) as the Attr parameter.
Note: FindFirst allocates resources (memory) which must be released by calling FindClose.
The following example uses an edit control, a button, a string grid, and seven check boxes. The check boxes correspond to the seven possible file attributes. When the button is clicked, the path specified in the edit control is searched for files matching the checked file attributes. The names and sizes of the matching files are inserted into the string grid.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TSearchRec sr;
int iAttributes = 0;
StringGrid1->RowCount = 1;
iAttributes |= faReadOnly * CheckBox1->Checked;
iAttributes |= faHidden * CheckBox2->Checked;
iAttributes |= faSysFile * CheckBox3->Checked;
iAttributes |= faVolumeID * CheckBox4->Checked;
iAttributes |= faDirectory * CheckBox5->Checked;
iAttributes |= faArchive * CheckBox6->Checked;
iAttributes |= faAnyFile * CheckBox7->Checked;
StringGrid1->RowCount = 0;
if (FindFirst(Edit1->Text, iAttributes, sr) == 0)
{
do
{
if ((sr.Attr & iAttributes) == sr.Attr)
{
StringGrid1->RowCount = StringGrid1->RowCount + 1;
StringGrid1->Cells[1][StringGrid1->RowCount-1] = sr.Name;
StringGrid1->Cells[2][StringGrid1->RowCount-1] = IntToStr(sr.Size);
}
} while (FindNext(sr) == 0);
FindClose(sr);
}
}
Hee 님이 쓰신 글 :
: 정말 잘몰라서 그러는데요...
: 조금더 자세히 알려주시면 안될까요...??
:
:
:
: 지나가는 사람 님이 쓰신 글 :
: :
: : 이건 답을 쉽게 찾을 수 있는건데... 쩝...
: :
: : C언어 책에서 한번 찾아보세요..
: :
: : 제 기억이 정확하다면.. FindFirst와 FindNext를 이용하면 됩니다.
: : 이때.. 속성을 디렉토리로 지정하면 됩니다.
: :
: : 이건 도스때도 쓰던거니까.. 아무 C언어 책같은데 잘 찾아보면 있을겁니다.
: : 아마도 헬프에도 있을거구요..
: :
: :
:
|