procedure TformIE.Button1Click(Sender: TObject);
var
sr: TSearchRec;
Item : TListItem;
begin
if FindFirst(shellTreeView.Path+'\*.*', faAnyFile, sr) = 0 then
begin
repeat
if (sr.Attr and faDirectory)<>0 then
begin
Item:=ListView.Items.Add;
Item.Caption:=sr.Name;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;结果:ListView 里面会多出两个文件夹: . 和 ..
请问怎么处理掉这两文件夹呢?
var
sr: TSearchRec;
Item : TListItem;
begin
if FindFirst(shellTreeView.Path+'\*.*', faAnyFile, sr) = 0 then
begin
repeat
if (sr.Attr and faDirectory)<>0 then
begin
Item:=ListView.Items.Add;
Item.Caption:=sr.Name;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;结果:ListView 里面会多出两个文件夹: . 和 ..
请问怎么处理掉这两文件夹呢?
var
sr: TSearchRec;
Item : TListItem;
begin
if FindFirst(shellTreeView.Path+'\*.*', faAnyFile, sr) = 0 then
begin
repeat
if (pos('.',sr.Name)>0) and (Length(copy(sr.Name,pos('.',sr.Name)+1,2))>=2) then
begin
Item:=ListView.Items.Add;
Item.Caption:=sr.Name;
//提取含有扩展名的文件
end
else
begin
if (pos('.',sr.Name)>0) then
else
begin
Item:=ListView.Items.Add;
Item.Caption:=sr.Name;
//提取文件文件夹或是不带扩展名的文件
end;
end;
until FindNext(sr) <> 0;
FindClose(sr);
end;
end;自己写了这个,目的达到了,但显得有些笨,有其他的好办法吗?
谢谢个位帮忙!!
if (sr.Name[1]<>'.')and(sr.Attr and faDirectory<>0) then