delphi中怎么用什么命令打开文件夹?

来源:百度知道 编辑:UC知道 时间:2024/05/21 09:42:06

扫描文件夹里面有哪些文件应该使用findfirst、findnext,下面是我程序里面的一个自定义函数,用来把指定目录下的文件清单写入一个字符串里面,可以writeln输出(writeln(DirListStr('c:\windows\*.exe'))),或者存放到memo里面。

function DirListStr(const FileName: string): string;
var SearchRec: TSearchRec; ok: integer; attrs: string[5];
begin
ok:=FindFirst(filename,$3f,SearchRec);
Result:='Directory of '+filename;
while ok=0 do begin
with SearchRec do begin
if Attr and $10 <> 0 then attrs[1]:='D' else attrs[1]:='-';
if Attr and $20 <> 0 then attrs[2]:='A' else attrs[2]:='-';
if Attr and $4 <> 0 then attrs[3]:='S' else attrs[3]:='-';
if Attr and $2 <> 0 then attrs[4]:='H' else attrs[4]:='-';
if Attr and $1 <> 0 then attrs[5]:='R' else attrs[5]:='-';
setlength(attrs,5);
Result:=Result+#13#10+attrs+' '+