procedure TForm1.Button1Click(Sender: TObject); var strFileName: string; // holds the name of the file to find FindFileData: TWin32FindData; // holds file information SearchHandle: THandle; // holds the search handle begin {clear any listed files} ListView1.Items.Clear; {if there was no file specified, then specify all files} if Edit2.GetTextLen = 0 then Edit2.Text:= '*.*'; {construct the filename string} strFileName:= DirectoryListBox2.Directory + '\' + Edit2.Text; {set the directory to the specified directory} SetCurrentDirectory(PChar(DirectoryListBox2.Directory)); {begin the search} SearchHandle:=FindFirstFile(PChar(strFileName), FindFileData); {continue searching for all matching files in the current directory} if (SearchHandle <> INVALID_HANDLE_VALUE) then repeat ListView1.Items.Add.Caption:=FindFileData.cFileName; until (FindNextFile(SearchHandle,FindFileData) = FALSE); {all files have been found, so close the search handle} Windows.FindClose(SearchHandle); end;
var i:integer; serchrec:tsearchrec; i:=findfirst('c:\*.*',0,searchrec); while i=0 do begin //找到 findnext(searchred); end;
var
strFileName: string; // holds the name of the file to find
FindFileData: TWin32FindData; // holds file information
SearchHandle: THandle; // holds the search handle
begin
{clear any listed files} ListView1.Items.Clear; {if there was no file specified, then specify all files}
if Edit2.GetTextLen = 0 then Edit2.Text:= '*.*'; {construct the filename string}
strFileName:= DirectoryListBox2.Directory + '\' + Edit2.Text; {set the directory to the specified directory}
SetCurrentDirectory(PChar(DirectoryListBox2.Directory)); {begin the search}
SearchHandle:=FindFirstFile(PChar(strFileName), FindFileData); {continue searching for all matching files in the current directory}
if (SearchHandle <> INVALID_HANDLE_VALUE) then
repeat
ListView1.Items.Add.Caption:=FindFileData.cFileName;
until (FindNextFile(SearchHandle,FindFileData) = FALSE); {all files have been found, so close the search handle}
Windows.FindClose(SearchHandle);
end;
i:integer;
serchrec:tsearchrec;
i:=findfirst('c:\*.*',0,searchrec);
while i=0 do
begin
//找到
findnext(searchred);
end;