首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

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

2012-05-20 
求:如何获取一文件夹中所有SWF文件如何获取一文件夹中所有SWF文件,并按文件名首字母排序放到一列表中[解决

求:如何获取一文件夹中所有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; 

热点排行