就是检测某某目录下的文件,然后生成一个文本
文本格式大概是这样的
文件夹名|文件名称|文件名称|这样下去
到下一个文件夹的时候在下一行同样的格式。

解决方案 »

  1.   

    //那去修改一下吧,写入文件过程你可以先把读到的信息保存在一个stringlist中 然后保存成文件procedure GetFileInfo(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);//文件名
          
        end
        else
        begin
          tmpstr := FindData.cFileName + '';
          if (tmpstr <> '.') and (tmpstr <> '..') then
          begin
             //文件夹
            tempFolder:=tempFolder+string(FindData.cFileName)+'\';
            GetFileInfo(pathname + '\' + FindData.cFileName);
          end;
        end;
        b := windows.FindNextFile(hf,FindData);
      end;
    end;
      

  2.   

    procedure GetFileList(AStrings: TStrings; ASourFile: string);
    var
      sour_path: string;
      FileRec: TSearchrec;
      tmpstr: string;
    begin
      sour_path := trim(ASourFile);
      if sour_path[Length(sour_path)] <> '\' then
        sour_path := sour_path + '\';  if not DirectoryExists(sour_path) then
      begin
        AStrings.Clear;
        exit;
      end;  tmpstr := sour_path;
      if FindFirst(sour_path + '*.*', faAnyfile, FileRec) = 0 then
        repeat
          if ((FileRec.Attr and faDirectory) <> 0) then
          begin
            if ((FileRec.Name <> '.') and (FileRec.Name <> '..')) then
            begin
              if tmpstr <> '' then
                AStrings.Add(tmpstr);
              tmpstr := '';
              GetFileList(AStrings, sour_path + FileRec.Name + '\');
            end;
          end
          else if ((FileRec.Attr and faDirectory) = 0) then
          begin
            tmpstr := tmpstr + ' | ' + FileRec.Name;
          end;    until FindNext(FileRec) <> 0;  FindClose(FileRec);
      if tmpstr <> '' then
        AStrings.Add(tmpstr);
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      Memo1.Lines.Clear;
      GetFileList(Memo1.Lines, 'E:\');
      Memo1.Lines.SaveToFile('c:\filelist.txt');
    end;
      

  3.   

    如果空文件夹不想保存,判断tmpstr最后一个是否为'\',是就表示是空目录