블로그 이미지
자료에 문제가 있을 경우, 확인하는대로 삭제처리 하겠습니다. 즐거운 하루 되시길...
04-28 21:01
Total
Today
Yesterday

카테고리

분류 전체보기 (199)
이야기방 (20)
공부방 (173)
개발노트&관련잡다구니 (6)
 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: 
 
: Match any one character
: Match 0, 1 or more characters

 
The Attributes may be set as follows: 
 
faAnyFile  : Any file
faReadOnly  : Read-only files
faHidden  : Hidden files
faSysFile  : System files
faVolumeID  : Volume ID files
faDirectory  : Directory files
faArchive  : Archive files

 
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 : 
 
Name  : Of the long name of the file found
Size  : The size of the file in bytes
Time  : Last modified date/time of the file
Attr  : The file attributes (as above)

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
 



Posted by 래채
, |