随笔 - 6  文章 - 129  trackbacks - 0
<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

常用链接

留言簿(14)

随笔档案(6)

文章分类(467)

文章档案(423)

相册

收藏夹(18)

JAVA

搜索

  •  

积分与排名

  • 积分 - 814152
  • 排名 - 49

最新评论

阅读排行榜

评论排行榜

copy:http://www.jackfeng.com/archives/276/

{-------------------------------------------------------------------------------
过程名:    MakeFileList 遍历文件夹及子文件夹
作者:      SWGWEB
日期:      2007.11.25
参数:      Path,FileExt:string   1.需要遍历的目录 2.要遍历的文件扩展名
返回值:    TStringList

   Eg:ListBox1.Items:= MakeFileList( 'E:\极品飞车','.exe') ;
       ListBox1.Items:= MakeFileList( 'E:\极品飞车','.*') ;
-------------------------------------------------------------------------------}
function MakeFileList(Path,FileExt:string):TStringList ;
var
sch:TSearchrec;
begin
Result:=TStringlist.Create;

if rightStr(trim(Path), 1) <> '\' then
    Path := trim(Path) + '\'
else
    Path := trim(Path);

if not DirectoryExists(Path) then
begin
    Result.Clear;
    exit;
end;

if FindFirst(Path + '*', faAnyfile, sch) = 0 then
begin
    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;

------------------------------------------------------------------------------------------------------------------------------------

字符截取函数LeftStr, MidStr, RightStr
这几个函数都包含在StrUtils中,所以需要uses StrUtils;
假设字符串是 Dstr := ’Delphi is the BEST’, 那么
LeftStr(Dstr, 5) := ’Delph’
MidStr(Dstr, 6, 7) := ’i is th’
RightStr(Dstr, 6) := ’e BEST’

~~~~~~~~~~~~~~~~~~~~~~~~~
function RightStr
    (Const Str: String; Size: Word): String;
begin
  if Size > Length(Str) then Size := Length(Str) ;
  RightStr := Copy(Str, Length(Str)-Size+1, Size)
end;
function MidStr
    (Const Str: String; From, Size: Word): String;
begin
  MidStr := Copy(Str, From, Size)
end;
function LeftStr
    (Const Str: String; Size: Word): String;
begin
  LeftStr := Copy(Str, 1, Size)
end;

这几个函数经常结合Pos, Length, Copy使用




posted on 2010-05-19 11:48 Ke 阅读(3491) 评论(0)  编辑  收藏 所属分类: delphi

只有注册用户登录后才能发表评论。


网站导航: