delphi遍历指定目录下指定类型文件的函数
来源:互联网 发布:大学物理网络课程 编辑:程序博客网 时间:2024/05/16 14:33
delphi遍历指定目录下指定类型文件的函数
作者:admin 来源:未知 日期:2010-5-8 11:02:46 人气:551 标签:
遍历指定目录下指定类型文件的函数
// ================================================================
// 遍历某个文件夹下某种文件,
// 使用说明
// _GetFileList(ListBox1.Items,'c:\*.doc');
// _GetFileList(MyTStringList,'c:\*.exe');
// ================================================================
procedure TForm1._GetFileList(AStrings: TStrings ; ASourFile: string);
var sour_path,sour_file: string;
TmpList:TStringList;
FileRec:TSearchrec;
begin
sour_path:=ExtractFilePath(ASourFile);
sour_file:=ExtractFileName(ASourFile);
if not DirectoryExists(sour_path) then
begin
AStrings.Clear;
exit;
end;
TmpList:=TStringList.Create;
TmpList.Clear;
if FindFirst(sour_path+sour_file,faAnyfile,FileRec) = 0 then
repeat
if ((FileRec.Attr and faDirectory) = 0) then
begin
TmpList.Add(sour_path+FileRec.Name)
end;
until FindNext(FileRec)<>0;
SysUtils.FindClose(FileRec);
AStrings.Assign(TmpList);
TmpList.Free;
end;
// ================================================================
// 遍历某个文件夹及子文件夹下某种文件,
// 使用说明
// _GetFileList(ListBox1.Items, 'c:\', '*.doc');
// _GetFileList(MyTStringList, 'c:\', '*.exe');
// ================================================================
procedure _GetFileList(AStrings: TStrings; ASourFile,
FileName: string);
var sour_path,sour_file: string;
TmpList:TStringList;
FileRec, subFileRec:TSearchrec;
i: Integer;
begin
if rightStr(trim(ASourFile), 1) <> '\' then
sour_path :=trim(ASourFile) + '\'
else
sour_path :=trim(ASourFile);
sour_file:= FileName;
if not DirectoryExists(sour_path) then
begin
AStrings.Clear;
exit;
end;
TmpList:=TStringList.Create;
TmpList.Clear;
if FindFirst(sour_path+'*.*',faAnyfile,FileRec) = 0 then
repeat
if ((FileRec.Attr and faDirectory) <> 0) then
begin
if ((FileRec.Name<> '.') and (FileRec.Name <> '..')) then
_GetFileList(AStrings, sour_path+ FileRec.Name + '\', sour_file);
end
else
if FindFirst(sour_path + FileName,faAnyfile,subFileRec) = 0 then
repeat
if ((subFileRec.Attr and faDirectory) = 0) then
TmpList.Add(sour_path+subFileRec.Name);
until FindNext(subFileRec)<>0;
until FindNext(FileRec)<>0;
FindClose(FileRec);
for i := 0 to TmpList.Count -1 do
AStrings.Add(TmpList.Strings[i]);
TmpList.Free;
end;
0 0
- delphi遍历指定目录下指定类型文件的函数
- 两个delphi下遍历指定目录下指定类型文件的函数
- 两个delphi下遍历指定目录下指定类型文件的函数
- 两个delphi下遍历指定目录下指定类型文件的函数
- 遍历指定目录下指定类型文件的函数
- 遍历指定目录下指定类型文件的方法集锦
- 转载遍历指定目录下所有指定类型的文件
- MFC 遍历目录下指定类型的文件并复制
- 遍历目录下的指定扩展名文件的函数
- Delphi 计算指定目录下所有文件的大小(遍历文件夹所有文件及目录)
- VC 遍历指定目录下的文件
- 遍历指定目录下的所有文件
- 遍历指定目录下指定格式的文件
- 使用QDir遍历指定目录下的指定文件
- 遍历读取指定文件夹下指定类型的所有文件
- 遍历读取指定文件夹下指定类型的所有文件
- 获取指定目录下的指定类型的文件
- 删除指定目录下指定类型的文件
- Flex之旅:第一部分:flex必备基础知识积累(4)---ArrayCollection, Array赋值写法
- [转] ASCII,Unicode,UTF-8,GB2312编码之间的关系
- 基于asp.net + easyui框架,js实现上传图片之前判断图片格式,同时实现预览,兼容各种浏览器+下载
- Linux系统中最实用的十大开源防火墙
- 数据库用裸设备做数据文件的一点记录
- delphi遍历指定目录下指定类型文件的函数
- 扩充String类(逐渐修改版)
- Python脚本日记
- flex: for...in和for...each区别
- CentOS5.4 安装php5.2.x 和 ZendOptimizer-3.3.9的方法,方便支持phpMyAdmin-3.2.2
- oracle killed会话不释放的问题
- 自制vim计时小插件: vtimer
- 用SetupDiGetClassDevs枚举设备
- 介绍几本as3.0的经典书籍