这是delphi的例子,你看看
procedure TForm1.Button1Click(Sender: TObject);var
sr: TSearchRec;
FileAttrs: Integer;
begin
StringGrid1.RowCount := 1;
if CheckBox1.Checked then
FileAttrs := faReadOnly
else
FileAttrs := 0;
if CheckBox2.Checked then
FileAttrs := FileAttrs + faHidden;
if CheckBox3.Checked then
FileAttrs := FileAttrs + faSysFile;
if CheckBox4.Checked then
FileAttrs := FileAttrs + faVolumeID;
if CheckBox5.Checked then FileAttrs := FileAttrs + faDirectory;
if CheckBox6.Checked then
FileAttrs := FileAttrs + faArchive;
if CheckBox7.Checked then FileAttrs := FileAttrs + faAnyFile; with StringGrid1 do
begin
RowCount := 0; if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then begin
repeat
if (sr.Attr and FileAttrs) = sr.Attr then
begin
RowCount := RowCount + 1;
Cells[1,RowCount-1] := sr.Name;
Cells[2,RowCount-1] := IntToStr(sr.Size);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);var
sr: TSearchRec;
FileAttrs: Integer;
begin
StringGrid1.RowCount := 1;
if CheckBox1.Checked then
FileAttrs := faReadOnly
else
FileAttrs := 0;
if CheckBox2.Checked then
FileAttrs := FileAttrs + faHidden;
if CheckBox3.Checked then
FileAttrs := FileAttrs + faSysFile;
if CheckBox4.Checked then
FileAttrs := FileAttrs + faVolumeID;
if CheckBox5.Checked then FileAttrs := FileAttrs + faDirectory;
if CheckBox6.Checked then
FileAttrs := FileAttrs + faArchive;
if CheckBox7.Checked then FileAttrs := FileAttrs + faAnyFile; with StringGrid1 do
begin
RowCount := 0; if FindFirst(Edit1.Text, FileAttrs, sr) = 0 then begin
repeat
if (sr.Attr and FileAttrs) = sr.Attr then
begin
RowCount := RowCount + 1;
Cells[1,RowCount-1] := sr.Name;
Cells[2,RowCount-1] := IntToStr(sr.Size);
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;
end;
解决方案 »
- 【散分贴】好久莫来啦,兄弟们可都安好?
- 菜鸟提问。。
- 如何去掉indy的错误提示
- 是重查询速度快还是查询得到数据再过滤要快呀?
- 如何得到每个框架的Document,(此题比较难,关注有分!)
- adoquery的 filter 属性如何使用 ?
- Delphi中COM的若幹問題!
- 请高手帮我看一下关于预览的程序!!
- 高分求救﹐我的畢業設計搞不定了﹐有誰做過人事信息維護系統﹐求系統分析文檔。
- 关于RichEdit
- 请问我要用进度条显示这个PcmtoWave(Pchar(FileName.Text),Pchar(FileName.text+'.wav'))函数执行的进度,应该怎样编程?
- 一个程序员关心的问题:月薪。
//Find Directory in Dir
var
FindHandle: THandle;
FindData: Win32_Find_Data;
procedure Add;
var
vDirName, vFullDirName: string;
begin
{ if FileExists(Dir + FindData.cFileName)
and (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY = 0)
and (FindData.dwFileAttributes and FILE_ATTRIBUTE_OFFLINE = 0)
and (FindData.dwFileAttributes and FILE_ATTRIBUTE_TEMPORARY = 0)
then}
vDirName := FindData.cFileName;
vFullDirName := Dir + vDirName;
if not((vDirName = '.') or (vDirName = '..') or (Pos(':\RECYCLED', Uppercase(vFullDirName)) > 0))
and DirectoryExists(vFullDirName) then begin
if FullDirName then
DirNames.Add(vFullDirName)
else
DirNames.Add(vDirName);
end;
end;
begin
Result := false;
Dir := IncludeTrailingBackSlash(Dir);
DirNames.Clear;
FindHandle := FindFirstFile(PChar(Dir + Mask), FindData);
if FindHandle <> 0 then begin
Add;
While FindNextFile(FindHandle, FindData) do Add;
Windows.FindClose(FindHandle);
if DirNames.Count > 0 then Result := true;
end;
end;