delphi中怎么用什么命令打开文件夹?
2个回答
展开全部
扫描文件夹里面有哪些文件应该使用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+' '+DateTimeToStr(FileDateToDateTime(time))+#9+IntToStr(size)+#9+Name;
end;
ok:=FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
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+' '+DateTimeToStr(FileDateToDateTime(time))+#9+IntToStr(size)+#9+Name;
end;
ok:=FindNext(SearchRec);
end;
FindClose(SearchRec);
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询