各位高手:請教在delphi中怎樣根據路徑取得該路徑下的文件名呢?急!急!

解决方案 »

  1.   

    如果知道文件名就可以用:ExtractFilename(s);
    如果不知道就可以用:FileListBox来加载数径里的文件列表,文件名:FileListBox.items[0];
      

  2.   

    s :=path;
    filename :=ExtractFileName(s);
      

  3.   

    楼上的方法得到的文件名包含扩展名~
    如果只想得到文件名~
    可以用 
    s := path;
    FileName := ChangeFileExt(ExtractFileName(s), '')以下给出我写的一个软件中枚举目录下所有.txt文件~
    并将文件名存储到指定文件中的过程~
    Path为路径~
    ListName是输出列表文件的文件名(不含扩展名)~
    *.txt为搜索文件的类型~
    楼主看着改吧~procedure TForm1.PreFileList(Path: string; ListName: string);
    var
      SR: TSearchRec;
      FileAttr: Integer;
      buf: TStringList;
    begin
      buf := TStringList.Create;
      FileAttr := faAnyFile;
      FindFirst(Path + '\*.txt', FileAttr, SR);
      if (SR.Name <> '.') and (Sr.Name <> '..') then
        buf.Add(ChangeFileExt(SR.Name, ''));
      while FindNext(SR) = 0 do
      begin
        if (SR.Name <> '.') and (Sr.Name <> '..') then
          if not (DirectoryExists(Path + '\' + SR.Name)) then
            buf.Add(ChangeFileExt(SR.Name, ''));
      end;
      buf.SaveToFile(AppDir + ListName + '.tmp');
      buf.Free;
    end;