目录怎么回自动变成文件,怪事?procedure TForm2.dispdir4(spath:string;node:TTreeNode);
var
 cnode:TTreeNode;
 ffd:WIN32_FIND_DATA ;
 hFind:THandle;
 Dest:string;
 hstr:string;
begin
if copy(spath,length(spath),1)<>'\' then
   spath:=spath+'\';
Dest:=Spath+'*.*';  hFind:=FindFirstFile(PChar(Dest),ffd);
  if hFind>0 then
   begin//1
    hstr:=ffd.cFileName;
     if ffd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY then
      begin//2
       if (ffd.cFileName[0]<>'.') then
        begin//3
          cnode:=tv1.Items.AddChild(Node,hstr );
          cnode.ImageIndex :=1;
          cnode.SelectedIndex :=cnode.ImageIndex;
          dispdir4( spath+hstr ,cnode);
        end;//3
      end//2
      else
      begin//22
        cnode:=tv1.Items.AddChild(Node,hstr );
        cnode.ImageIndex :=0;
        cnode.SelectedIndex :=cnode.ImageIndex;
      end;//22
  end;//1
 while FindNextFile(hFind,ffd)=true  do
  begin//4
   hstr:=ffd.cFileName;
     if ffd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY then
      begin//2
       if (ffd.cFileName[0]<>'.') then
         begin//3
          cnode:=tv1.Items.AddChild(Node,hstr );
          cnode.ImageIndex :=1;
          cnode.SelectedIndex :=cnode.ImageIndex;
          dispdir4( spath+hstr,cnode);
         end;//3
      end//2
      else
      begin//22
        cnode:=tv1.Items.AddChild(Node,hstr );
        cnode.ImageIndex :=0;
        cnode.SelectedIndex :=cnode.ImageIndex;
      end;//22
  end;//4end;
我用这段API读入C:\Documents and Settings\Administrator发现一个问题:凡是:1只读的,2隐藏的,3还有Cookies文件都会被读成文件的形式如图:http://www.bwkj.net/ddiscussion/findnexterror1.jpg我的程序应该如何修正?

解决方案 »

  1.   

    只是图标换了吧? 现在没delphi不好调。
      

  2.   

    Delphi 的 FindFirst也不错啊,FindFirs('c:\*.*', Attrib, TsearchREC);是不是索引乱了?
      

  3.   

    ffd.dwFileAttributes包含了复合属性值,可能是FILE_ATTRIBUTE_SYSTEM和FILE_ATTRIBUTE_ARCHIVE 和FILE_ATTRIBUTE_READONLY和FILE_ATTRIBUTE_DIRECTORY的复合。所以应将程序中的if ffd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY 改为
    if (ffd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY)=FILE_ATTRIBUTE_DIRECTORY
     
    我运行了该段代码,显示C:\下的目录和文件,发现速度非常慢,要15秒左右才能出来,这一点不知道有没有办法改进,另外怎样才能让文件以自己的图标形式显示出来?