要得到所有C:\Documents and Settings\aaa\Local Settings\Temporary Internet Files下的swf文件,把文件名放到LISTBOX里,好像不行啊。我用下面的方法,其它路径的文件是可以的,可这个目录的文件却是不行的,高手帮忙啊
var
  Path  : string;
  SR    : TSearchRec;
begin
  Path:= 文件夹路径;
  Self.ListBox1.Items.Clear;
  if FindFirst(Path+'\*.swf',faArchive,SR)=0 then
     repeat
       ListBox1.Items.Add(path+'\'+SR.Name);
     until FindNext(RS) <> 0;
  FindClose(RS);

解决方案 »

  1.   

    楼主真不够意思,分这么少,结贴时能不能多加点分啊:function GetAllFile(const Path: string; FileEx: string = '*.*'): TStringList;
    var
      f: TSearchRec;
      Ret: Integer;
    begin
      FileEx := UpperCase(FileEx);
      Result := TStringList.Create;
      Ret := FindFirst(Path + '\*.*', faAnyFile, f);
      while Ret = 0 do
      begin
        if f.Attr = faDirectory then
        begin
          if (f.Name <> '.') and (f.Name <> '..') then
            GetAllFile(Path + '\' + f.Name)
        end
        else
          if (FileEx = '*.*') or (UpperCase(ExtractFileExt(f.Name)) = FileEx) then        Result.Append(Path + '\' + f.Name);    Ret := FindNext(f)
      end;
      FindClose(f)
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ListBox1.Items.Assign(GetAllFile('c:\windows', '.swf));
    end;
      

  2.   

    先将路径改成短路径试试:
    function
      GetShortName( sLongName : string )
      : string;
    var
      sShortName    : string;
      nShortNameLen : integer;
    begin
      SetLength( sShortName,
                 MAX_PATH );  nShortNameLen :=
        GetShortPathName(
          PChar( sLongName ),
          PChar( sShortName ),
          MAX_PATH - 1 );  if( 0 = nShortNameLen )then
      begin
        // handle errors...
      end;  SetLength( sShortName,
                 nShortNameLen );  Result := sShortName;
    end;