一个文件夹有10个文件,如何把这些文件的文件名取来,存到一个数组中?

解决方案 »

  1.   

    FindFirst
    FindNextDelphi Help 中的一个例子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;
      

  2.   

    用filelistbox控件,再赋值给stringlist
      

  3.   

    var
      i:integer;
      ts:TStringList;
    begin
      ts:=TStringList.Create;
      for  i:=0 to FileListBox1.Count-1 do begin
        if FileListBox1.Selected[i] then ts.Add(FileListBox1.Items[i]);
      end;
    ...
      ts.Free;
    end;