用delphi实现读取foxmail的地址。
//今日读了各位仁兄之文章,深感黑道光荣,以下是狗兄我自写代码在d6上实现,也就不加赘述,各位参考着看代码吧。不过,在遍历ind文件时好像还有问题,请各位兄兄斧正!谢! unit unit1; interface uses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; type tform1 = class(tform) button1: tbutton; memo1: tmemo; button2: tbutton; procedure button1click(sender: tobject); procedure formcreate(sender: tobject); procedure formdestroy(sender: tobject); procedure button2click(sender: tobject); private { private declarations } public procedure findfiles(startdir: string); procedure getemail(filestr:string); { public declarations } end; var form1: tform1; implementation {$r *.dfm} procedure tform1.button1click(sender: tobject); var headbuf:array[0..$41] of char; recbuf:array[0..$b1] of char; name:array[0..$21] of char; email:array[0..$41] of char; f:file; i:integer; begin assignfile(f,extractfilepath(application.exename)+address.ind); // f:=tfilestream.create(extractfilepath(application.exename)+address.ind,fmopenreadwrite); reset(f,1); seek(f,$40); while not eof(f) do begin for i :=0 to $21 do name[i]:=char(0); for i:=0 to $41 do email[i]:=char(0); //blockread(fromf, buf, sizeof(buf), numread); blockread(f,recbuf,$b0); if recbuf[$4]=1 then continue; if recbuf[$11]=1 then continue; for i:=0 to ord(recbuf[$21]) do begin name[i]:=recbuf[i+$13]; end; for i:=0 to ord(recbuf[$33]) do email[i]:=recbuf[i+$34]; memo1.lines.add(name); memo1.lines.add(********************); memo1.lines.add(email); end; closefile(f); end; procedure tform1.findfiles(startdir: string); var sr: tsearchrec; //用来储存返回的文件的一些数据 isfound: boolean;//做为一个标志 begin isfound :=findfirst(startdir+*.ind, faanyfile-fadirectory, sr) = 0; //在startdir里面查找htm文件 while isfound do begin //如果找到htm文件 // getemailaddress(startdir+sr.name); getemail(startdir+sr.name); //这里调用我们自己定义的函数,传递的参数是startdir+sr.name也就是该文件的绝对路径。 //注意,这里的函数 getemailaddress我们等一下再来描述 isfound := findnext(sr) = 0; //继续查找htm文件,只到标志isfound为false end; findclose(sr); isfound := findfirst(startdir+*.*, faanyfile, sr) = 0; //现在是查找所有的文件 while isfound do begin if ((sr.attr and fadirectory) <> 0) and(sr.name[1] <> .) then findfiles(startdir+sr.name+\); //如果该文件是目录,并且不是"."或者"..",那么就在该目录里继续查找,也就是在这里递归了。 isfound := findnext(sr) = 0; end; findclose(sr); end; procedure tform1.formcreate(sender: tobject); begin end; procedure tform1.formdestroy(sender: tobject); begin end; procedure tform1.getemail(filestr: string); var headbuf:array[0..$41] of char; recbuf:array[0..$b1] of char; name:array[0..$21] of char; email:array[0..$41] of char; f:file; i:integer; begin assignfile(f,filestr); reset(f,1); seek(f,$40); while not eof(f) do begin for i :=0 to $21 do name[i]:=char(0); for i:=0 to $41 do email[i]:=char(0); //blockread(fromf, buf, sizeof(buf), numread); blockread(f,recbuf,$b0); if recbuf[$4]=1 then continue; if recbuf[$11]=1 then continue; for i:=0 to ord(recbuf[$21]) do begin name[i]:=recbuf[i+$13]; end; for i:=0 to ord(recbuf[$33]) do email[i]:=recbuf[i+$34]; memo1.lines.add(name); memo1.lines.add(********************); memo1.lines.add(email); end; closefile(f); end; procedure tform1.button2click(sender: tobject); begin findfiles(d:\foxmail\); end; end. ()
© 2006 www.java-asp.net