var sr:TSearchRec; Found:integer; path:string; begin path:='D:\'; found:=FindFirst(path+'*.*',faAnyFile,sr); while (found=0) do begin if sr.Name[1]<>'.' then begin if ((sr.Attr and faDirectory)=16) then Memo1.Lines.Add(sr.Name) end; found:=FindNext(sr); end; end;
类似http://community.csdn.net/Expert/topic/4679/4679222.xml?temp=.893902
2.递归一下就可以了。
比如:有这样一个目录层次
D:\
MyMusic\
track01.mp3
track02.mp3
track03.mp3
MyMovie\
MyFatherAndMother.avi
Love\
Love01.rmvb
Love02.rmvb
Action\
Lixiaolong1.rm
Lixiaolong2.rm现在我想达到的目的是 找出D:\ 根目录下的目录名称(即:MyMusic和MyMovie),不包括文件名和子目录名称,请问怎样实现?
Found:integer;
path:string;
begin
path:='D:\';
found:=FindFirst(path+'*.*',faAnyFile,sr);
while (found=0) do
begin
if sr.Name[1]<>'.' then
begin
if ((sr.Attr and faDirectory)=16) then
Memo1.Lines.Add(sr.Name)
end;
found:=FindNext(sr);
end;
end;