//那去修改一下吧,写入文件过程你可以先把读到的信息保存在一个stringlist中 然后保存成文件procedure GetFileInfo(pathname: string); var FindData: TWin32FindData; hf:THandle; b:boolean; tmpstr:string; tempFolder:string; str:string; begin hf := Windows.FindFirstFile(PChar(pathname + '\*.*'), FindData); if hf = INVALID_HANDLE_VALUE then exit; b := true; while b do begin if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then begin str:=string(FindData.cFileName);//文件名
end else begin tmpstr := FindData.cFileName + ''; if (tmpstr <> '.') and (tmpstr <> '..') then begin //文件夹 tempFolder:=tempFolder+string(FindData.cFileName)+'\'; GetFileInfo(pathname + '\' + FindData.cFileName); end; end; b := windows.FindNextFile(hf,FindData); end; end;
procedure GetFileList(AStrings: TStrings; ASourFile: string); var sour_path: string; FileRec: TSearchrec; tmpstr: string; begin sour_path := trim(ASourFile); if sour_path[Length(sour_path)] <> '\' then sour_path := sour_path + '\'; if not DirectoryExists(sour_path) then begin AStrings.Clear; exit; end; tmpstr := sour_path; if FindFirst(sour_path + '*.*', faAnyfile, FileRec) = 0 then repeat if ((FileRec.Attr and faDirectory) <> 0) then begin if ((FileRec.Name <> '.') and (FileRec.Name <> '..')) then begin if tmpstr <> '' then AStrings.Add(tmpstr); tmpstr := ''; GetFileList(AStrings, sour_path + FileRec.Name + '\'); end; end else if ((FileRec.Attr and faDirectory) = 0) then begin tmpstr := tmpstr + ' | ' + FileRec.Name; end; until FindNext(FileRec) <> 0; FindClose(FileRec); if tmpstr <> '' then AStrings.Add(tmpstr); end;procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Lines.Clear; GetFileList(Memo1.Lines, 'E:\'); Memo1.Lines.SaveToFile('c:\filelist.txt'); end;
var
FindData: TWin32FindData;
hf:THandle;
b:boolean;
tmpstr:string;
tempFolder:string;
str:string;
begin
hf := Windows.FindFirstFile(PChar(pathname + '\*.*'), FindData);
if hf = INVALID_HANDLE_VALUE then exit;
b := true;
while b do
begin
if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
begin
str:=string(FindData.cFileName);//文件名
end
else
begin
tmpstr := FindData.cFileName + '';
if (tmpstr <> '.') and (tmpstr <> '..') then
begin
//文件夹
tempFolder:=tempFolder+string(FindData.cFileName)+'\';
GetFileInfo(pathname + '\' + FindData.cFileName);
end;
end;
b := windows.FindNextFile(hf,FindData);
end;
end;
var
sour_path: string;
FileRec: TSearchrec;
tmpstr: string;
begin
sour_path := trim(ASourFile);
if sour_path[Length(sour_path)] <> '\' then
sour_path := sour_path + '\'; if not DirectoryExists(sour_path) then
begin
AStrings.Clear;
exit;
end; tmpstr := sour_path;
if FindFirst(sour_path + '*.*', faAnyfile, FileRec) = 0 then
repeat
if ((FileRec.Attr and faDirectory) <> 0) then
begin
if ((FileRec.Name <> '.') and (FileRec.Name <> '..')) then
begin
if tmpstr <> '' then
AStrings.Add(tmpstr);
tmpstr := '';
GetFileList(AStrings, sour_path + FileRec.Name + '\');
end;
end
else if ((FileRec.Attr and faDirectory) = 0) then
begin
tmpstr := tmpstr + ' | ' + FileRec.Name;
end; until FindNext(FileRec) <> 0; FindClose(FileRec);
if tmpstr <> '' then
AStrings.Add(tmpstr);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Clear;
GetFileList(Memo1.Lines, 'E:\');
Memo1.Lines.SaveToFile('c:\filelist.txt');
end;