delphi中如何生成一个目录(包括子目录)的文件列表

delphi中如何生成一个目录(包括子目录)的文件列表,第1张

分类: 电脑/握旦网络 >>程序设计 >>其他编程语言

问旁启题描述:

使用delphi如何生成一个目录(包括子目录)的文件列表呢,就象一些播放器那样,指定一个运皮如目录,就可以把目录及子目录下所有的音乐文件添加到列表里.

解析:

function FileList(Path: stringAttr: Integer = FAAnyfile): TStrings

var

SR: TSearchRec

begin

Result := TStringList.Create

if Path[Length(Path)] <>'\' then

Path := Path + '\'

if (Attr and FADirectory) <>FADirectory then

Attr := Attr or FADirectory

if FindFirst(Path + '*.*', Attr, SR) = 0 then

repeat

if (SR.Attr and FADirectory) = FADirectory then begin

if (SR.Name <>'.') and (SR.Name <>'..') then

Result.AddStrings(FileList(Path + SR.Name))

end

else

Result.Add(Path + SR.Name)

until FindNext(SR) <>0

FindClose(SR)

end

一种是,将如喊数据库文件路径设置成,当前程序下的目录+data\db1.mdb

二是每次调用openPictureDailog1后用chdir()渣举野改回当前程序目录

即:chdir(extractfilepath(paramstr(0)))

第一种答肆可以窗口创建事件中用:extractfilepath(paramstr(0))+data\db1.mdb作为数据库文件路径


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12371068.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存