function FindFirst
( const FileMask : string; Attributes : Integer; var SearchResult : TSearchRec ) : Integer;
Description | ||||||||||||||||||||||||||
The FindFirst function searches for files matching aFileMask and Attributes, returning the first match (if found) in SearchResult. The Attributes define files to search for in addition to regular files. If a match is found, then the return value is 0, otherwise, it is negative (and the result record is not filled in). The FileMask may contain a path, as well as a file name. The file name may contain wild cards:
The Attributes may be set as follows:
You may set Attributes from one or more of the above by concatenating them. The SearchResult record comprises many fields. Some are used by subsequent calls to FindNext. Others are available to your program :
|
Notes |
Warning : you must call FindClose after a successfulFindFirst when you have finished searching (finished callingFindNext). This frees up resources held by the find process (such as the SearchResult record). If the FileMask contains no path information, then the search is in the current directory. Because the Attributes parameter defines additional file types to search for, you should filter the results Attr value to select only the desired file types. |
Example code : Find all Unit1.d* regular files in the current directory |
var searchResult : TSearchRec; begin // Try to find regular files matching Unit1.d* in the current dir if FindFirst('Unit1.d*', faAnyFile, searchResult) = 0 then begin repeat ShowMessage('File name = '+searchResult.Name); ShowMessage('File size = '+IntToStr(searchResult.Size)); until FindNext(searchResult) <> 0; // Must free up resources used by these successful finds FindClose(searchResult); end; end; |
Show full unit code |
File name = Unit1.dcu File size = 4382 File name = Uni1.dfm File size = 524 File name = Uni1.ddp File size = 51 |
Example code : Find all directories above and including the current one |
var searchResult : TSearchRec; begin // Try to find directories above the current directory SetCurrentDir('..'); if FindFirst('*', faDirectory, searchResult) = 0 then begin repeat // Only show directories if (searchResult.attr and faDirectory) = faDirectory then ShowMessage('Directory = '+searchResult.Name); until FindNext(searchResult) <> 0; // Must free up resources used by these successful finds FindClose(searchResult); end; end; |
Show full unit code |
Directory = . Directory = .. Directory = Bin Directory = Help Directory = Projects Directory = Demos Directory = Lib Directory = Objrepos Directory = MergeModules Directory = Imports Directory = Source Directory = Rave5 Directory = Ocx |
'공부방 > Delphi' 카테고리의 다른 글
[델파이] 기본 컴포넌트 (0) | 2010.07.14 |
---|---|
[델파이] 문자열 관련 함수 (0) | 2010.05.18 |
[델파이] POS (0) | 2010.05.13 |
[델파이] 델파이7 Quick Report 설치하기 (TQRChart 도~) (0) | 2010.05.08 |
[델파이] 델파이7 Indy 10 컴포넌트 설치하기 (0) | 2010.05.08 |