L
lizheng
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.FindFile(path:string);
var
SearchRec: TSearchRec;
path1:string;
err:integer;
begin
try
err:=FindFirst(path+'*.*',faAnyFile, SearchRec);
while err = 0 do
begin
if SearchRec.Name[1]<>'.' then begin
if ((SearchRec.Attr and fadirectory)>0) AND (SearchRec.Name[1]<>'.') then
begin
table1.Append;
table1.FieldByName('文件编号').asinteger:=wenjianNO;
table1.FieldByName('文件名称').asstring:=searchrec.Name;
table1.FieldByName('文件类型').asstring:='文件夹';
table1.FieldByName('光盘编号').asinteger:=strtoint(form2.Edit2.Text);
wenjianNO:=wenjianNO+1;
try
path1:=path+String(SearchRec.Name)+'/';
Form1.FindFile(path1);
except
exit;
end;
end
else
table1.Append;
table1.FieldByName('文件编号').asinteger:=wenjianNO;
table1.FieldByName('文件名称').asstring:=searchrec.Name;
table1.FieldByName('文件类型').asstring:=ExtractFileExt(SearchRec.Name);
table1.FieldByName('光盘编号').asinteger:=strtoint(form2.Edit2.Text);
wenjianNO:=wenjianNO+1;
end;
err:= FindNext(SearchRec);
end;
finally
FindClose(SearchRec);
end;
end;
每次运行时,在DBGRID中文件夹总是会出现两次,就是说,若lz是一个文件夹,
则在运行后DBGRID中回记录成
文件编号 文件名称 文件类型 存入时间 所属文件夹 光盘编号
4 lz 文件夹 43
...
12 lz 43
...
而且如果用文件来记录(如下)就不会出现这种错误
procedure TForm1.FindFile(path:string);
var
SearchRec: TSearchRec;
path1:string;
err:integer;
begin
try
err:=FindFirst(path+'*.*',faAnyFile, SearchRec);
while err = 0 do
begin
if SearchRec.Name[1]<>'.' then begin
s:=string(Searchrec.Name);
if ((SearchRec.Attr and fadirectory)>0) AND (SearchRec.Name[1]<>'.') then
begin
writeln(f,'');
writeln(f,'文件夹<'+s+'>');
try
path1:=path+String(SearchRec.Name)+'/';
Form1.FindFile(path1);
except
exit;
end;
end
else
writeln(f,s+' '+IntToStr(Searchrec.size));
end;
err:= FindNext(SearchRec);
end;
finally
FindClose(SearchRec);
writeln(f,'');
end;
end;
我百思不得其解,请帮老弟查查错.
var
SearchRec: TSearchRec;
path1:string;
err:integer;
begin
try
err:=FindFirst(path+'*.*',faAnyFile, SearchRec);
while err = 0 do
begin
if SearchRec.Name[1]<>'.' then begin
if ((SearchRec.Attr and fadirectory)>0) AND (SearchRec.Name[1]<>'.') then
begin
table1.Append;
table1.FieldByName('文件编号').asinteger:=wenjianNO;
table1.FieldByName('文件名称').asstring:=searchrec.Name;
table1.FieldByName('文件类型').asstring:='文件夹';
table1.FieldByName('光盘编号').asinteger:=strtoint(form2.Edit2.Text);
wenjianNO:=wenjianNO+1;
try
path1:=path+String(SearchRec.Name)+'/';
Form1.FindFile(path1);
except
exit;
end;
end
else
table1.Append;
table1.FieldByName('文件编号').asinteger:=wenjianNO;
table1.FieldByName('文件名称').asstring:=searchrec.Name;
table1.FieldByName('文件类型').asstring:=ExtractFileExt(SearchRec.Name);
table1.FieldByName('光盘编号').asinteger:=strtoint(form2.Edit2.Text);
wenjianNO:=wenjianNO+1;
end;
err:= FindNext(SearchRec);
end;
finally
FindClose(SearchRec);
end;
end;
每次运行时,在DBGRID中文件夹总是会出现两次,就是说,若lz是一个文件夹,
则在运行后DBGRID中回记录成
文件编号 文件名称 文件类型 存入时间 所属文件夹 光盘编号
4 lz 文件夹 43
...
12 lz 43
...
而且如果用文件来记录(如下)就不会出现这种错误
procedure TForm1.FindFile(path:string);
var
SearchRec: TSearchRec;
path1:string;
err:integer;
begin
try
err:=FindFirst(path+'*.*',faAnyFile, SearchRec);
while err = 0 do
begin
if SearchRec.Name[1]<>'.' then begin
s:=string(Searchrec.Name);
if ((SearchRec.Attr and fadirectory)>0) AND (SearchRec.Name[1]<>'.') then
begin
writeln(f,'');
writeln(f,'文件夹<'+s+'>');
try
path1:=path+String(SearchRec.Name)+'/';
Form1.FindFile(path1);
except
exit;
end;
end
else
writeln(f,s+' '+IntToStr(Searchrec.size));
end;
err:= FindNext(SearchRec);
end;
finally
FindClose(SearchRec);
writeln(f,'');
end;
end;
我百思不得其解,请帮老弟查查错.