如何得到一个指定目录下的所有文件名(50分)

  • 主题发起人 主题发起人 螃蟹
  • 开始时间 开始时间

螃蟹

Unregistered / Unconfirmed
GUEST, unregistred user!
如何得到一个指定目录下的所有文件名
 
StopSearch: Boolean;
Found: TSearchRec;
Dir: string;
Finished: Integer; //Result of Finding
files: TStrings;

if not DirectoryExists(Dir) then exit;
Files := TStringList.Create;
StopSearch := False;
Finished := FindFirst(Dir + '*.ini', 63, Found);
while (Finished = 0) and not (StopSearch) do
begin
if (Found.Name[1] <> '.') then Files.Add(Found.Name);
Finished := FindNext(Found);
end;
//end the search process.
FindClose(Found);
 
这一句应该是
Finished := FindFirst(Dir + '*.*', 63, Found);
 
procedure TMain.searchfile(apath:string);
var
FSearchRec,DSearchRec:TSearchRec;
FindResult:integer;
f:file of byte;
begin
findresult:=findfirst(Apath+'*.*',faanyfile,fsearchrec);
try
while findresult=0 do
begin
memo1.lines.add(fsearchrec.Name);//用memo存放所有文件名
assignfile(f,Apath+fsearchrec.Name);
Reset(f);
closefile(f);
findresult:=findnext(fsearchrec)
end;
findresult:=findfirst(apath+'*.*',fadirectory,dsearchrec);
while findresult=0 do
findresult:=findnext(dsearchrec);
finally
findclose(fsearchrec);
end;
end;
 
1)使用FindFirst、FindNext、FindClose寻找,楼上的兄弟们都说了;
2)使用文件列表控件,设置目录,然后随便都吧!
 
procedure TForm1.Button1Click(Sender: TObject);
procedure ReadFileName(var MyFileList : TStringList; const AnyFile:String);
var
Found:integer;
SearchResult:TSearchRec;
begin
if FileGetAttr(AnyFile)<>faDirectory then begin
MyFileList.Add(AnyFile);
Exit;
end;
Found:=FindFirst(AnyFile+'/*.*',faAnyFile,SearchResult);
while Found=0 do begin
if (SearchResult.Name<>'.')and(SearchResult.Name<>'..') then ReadFileName(MyFileList,AnyFile+'/'+SearchResult.Name);
Found:=FindNext(SearchResult);
end;
if (SearchResult.Name<>'.')and(SearchResult.Name<>'..') then FindClose(SearchResult);
end;
var
MyFileList : TStringList;
begin
MyFileList := TStringList.Create;
ReadFileName(MyFileList,'c:/');
end;
 
接受答案了.
 
我想搜别的机器上的怎么办?
例如搜索服务器上的: "//MyServer/music"
该怎么办?
 
后退
顶部