一个文件夹中包含多个子文件夹,现在我要选择这些子文件夹中的所有.xml文件,如何实现呢?(主文件夹中包含N多子文件夹,每个子文件夹中有一个XML文件,我想把这些文件名包括路径列在memo或或记在strlist中)。谢谢!!

解决方案 »

  1.   

    procedure GetXMLFile(pathname: string);
    var
      FindData: TWin32FindData;
      hf:THandle;
      b:boolean;
      tmpstr:string;
      tempFolder:string;
      str:string;
    begin
      hf := Windows.FindFirstFile(PChar(pathname + '\*.*'), FindData);
      if hf = INVALID_HANDLE_VALUE then exit;
      b := true;
      while b do
      begin
        if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
        begin
          str:=string(FindData.cFileName);
          if length(str)>5) and ((copy(str,length(str)-3,4)='.xml'
          begin
            self.ListBox1.Items.Add(PathName+'\'+string(FindData.cFileName));
          end;
        end
        else
        begin
          tmpstr := FindData.cFileName + '';
          if (tmpstr <> '.') and (tmpstr <> '..') then
          begin
            tempFolder:=tempFolder+string(FindData.cFileName)+'\';
            GetXMLFile(pathname + '\' + FindData.cFileName);
          end;
        end;
        b := windows.FindNextFile(hf,FindData);
      end;
    end;
      

  2.   

    这里的参数pathname指的是N多子文件夹的父文件夹吗