我想打开一个文件,从中读取数据,而这个文件名中有两位是不固定的,如(Sp1600??.633)类型,各位高手,看看如何打开它??

解决方案 »

  1.   

    if opendialog1.execute then ...
      

  2.   

    用循环判断
    function FileSearch(const Name, DirList: string): string;
      

  3.   

    说明一点,这是一类报文,后两位是不固定的,因为所有的报文都放在一个目录底下,有可能出现文件名相似的情况(如Sp160001.633,Sp160002.633,时间相差一个月)我们需要每天自动监测到当日的报文,判断后读取资料。现在的问题是,我能用通配符判断出当日的文件是否存在:
    datetostr(filedatetodatetime(fileage('sp1600??.631')))=datetostr(now) 
    就是无法读取sp1600??.631。
    换个说法,在知道这个文件确实存在的前提下,如何得知具体的文件名,这样问题就解决了。
    各位高手,想想办法!
      

  4.   

    用FINDFIRST,FINDNEXT试试
    function FindFirst(const Path: string; Attr: Integer; var F: TSearchRec): Integer;type 
    TSearchRec = record
    Time: Integer;
    Size: Integer;
    Attr: Integer;
    Name: TFileName;
    ExcludeAttr: Integer;
    FindHandle: THandle;
    FindData: TWin32FindData;
    end;令Name:='sp1600??.631'
      

  5.   

    var
      sr: TSearchRec;
    begin
      if findfirst('f:\Sp1600??.633',faAnyFile,sr)=0 then
        showmessage(sr.Name);
      while FindNext(sr) = 0 do
        showmessage(sr.Name);     //通过sr可以取得文件名
      FindClose(sr);
    end;