读书人

求:怎么获取一文件夹中所有SWF文件

发布时间: 2012-05-20 16:03:12 作者: rapoo

求:如何获取一文件夹中所有SWF文件
如何获取一文件夹中所有SWF文件,并按文件名首字母排序放到一列表中

[解决办法]
findfirst,findnext,指定文件后缀,看帮助
[解决办法]

Delphi(Pascal) code
function MakeFileList(Path,FileExt:string):TStringList ;varsch:TSearchrec;s:string;begin  Result:=TStringlist.Create;  s:=Copy(Path,Length(Path),1);if s <> '\' then    Path := trim(Path) + '\'else    Path := trim(Path);if not DirectoryExists(Path) thenbegin    Result.Clear;    exit;end;if FindFirst(Path + '*', faAnyfile, sch) = 0 thenbegin    repeat       Application.ProcessMessages;       if ((sch.Name = '.') or (sch.Name = '..')) then Continue;       if DirectoryExists(Path+sch.Name) then       begin         Result.AddStrings(MakeFileList(Path+sch.Name,FileExt));       end       else       begin         if (UpperCase(extractfileext(Path+sch.Name)) = UpperCase(FileExt)) or (FileExt='.*') then         Result.Add(Path+sch.Name);       end;    until FindNext(sch) <> 0;    SysUtils.FindClose(sch);end;end;procedure TForm1.Button1Click(Sender: TObject);beginlistbox1.Items:=MakeFileList(Edit1.Text,Edit2.Text);end;
[解决办法]
这个也试试,不过貌似区分大小写的

Delphi(Pascal) code
procedure   TForm1.GetPathFiles(ps:   string;   Lst: TStrings);var  dt:_WIN32_FIND_DATAA;  h:Cardinal;  s:string;begin try  if ps[length(ps)] <> '\' then    ps:=ps+'\';  s:=ps+'*.*';  h:=findfirstfile(pchar(s),dt);  if h<>INVALID_HANDLE_VALUE then  begin  repeat  if   (dt.cFileName[0]   <>   '.')   thenif(dt.dwFileAttributes   and   FILE_ATTRIBUTE_DIRECTORY   <>   0)   then getPathFiles(ps+dt.cFileName,   lst)elseif (copy(dt.cFileName,length(trim(dt.cFileName))-2,3)='swf')  thenbeginlst.Add(ps+dt.cFileName); end;until   not   findnextfile(h,dt);windows.FindClose(h);end;except end;end; 

读书人网 >.NET

热点推荐