很多人想要的代码!(50分)

  • 主题发起人 主题发起人 Carem
  • 开始时间 开始时间
C

Carem

Unregistered / Unconfirmed
GUEST, unregistred user!
是个很久以前就有的东西,一直没有去试验,今日做起来老是不行,作者说可以在系统<br>目录下产生maillist.lst,但是我不行,我肯定错了,但是错那里了?请各位指教!<br><br>program zrzj;<br>uses<br>&nbsp; windows,<br>&nbsp; messages,<br>&nbsp; Registry,<br>&nbsp; sysutils,<br>&nbsp; shellapi,<br>&nbsp; inifiles;<br><br>{$R *.res}<br>var<br>HK:HKEY;<br>IeCache:array[0..255] of char;<br>IeCacheLen:integer;<br>S:string;<br><br>procedure WriteAddress(Address:string);<br>var<br>F:textfile;<br>S,Str:string;<br>CanWrite:boolean;<br>Path:array[0..255] of char;<br>begin<br>GetwindowsDirectory(path,256);<br>//首先取得系统目录,到时候把email地址列表文件保存到这里。<br>Str:=Strpas(Path);<br>CanWrite:=true;<br>AssignFile(F,Str+'/maillist.lst');<br>if FileExists(Str+'/maillist.lst')=false then<br>&nbsp; &nbsp;begin<br>//如果不存在maillist.lst,则信建一个文件maillist.lst来存放email地址。<br>&nbsp; &nbsp;Rewrite(F);<br>&nbsp; &nbsp;writeln(F,Address);<br>&nbsp; &nbsp;Closefile(F);<br>&nbsp; &nbsp;exit;<br>&nbsp; &nbsp;end else <br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;Reset(f); <br>&nbsp; &nbsp; &nbsp; &nbsp;while not Eof(F) do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Readln(F,S);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Address=S then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CanWrite:=false; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseFile(F); <br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>//上面用来和文件里以经存在的地址一个一个的进行效验,如果不存在就写到列表里去。 <br>if CanWrite then<br>&nbsp; &nbsp;begin <br>&nbsp; &nbsp;Append(F);<br>&nbsp; &nbsp;Writeln(F,Address); <br>&nbsp; &nbsp;CloseFile(F);<br>&nbsp; &nbsp;end; <br>end;<br><br>procedure GetEmailAddress(FileName:string);<br>var<br>F:textfile;<br>S:string;//用来装每次读一行的字符串<br>Address:string;//得到的email地址<br>i,Position:integer;<br>begin<br>AssignFile(F,FileName);<br>Reset(f);<br>while not Eof(f) do<br>begin<br>Address:='';<br>//首先清空address<br>Readln(f,s);<br>//读取一行字符串到s中<br>Position:=Pos('mailto:',S);<br>//查找首个"mailto:"在s中的地址,如果一行中含有多个"mailto:"则需要你自己修改修改<br>if Position &gt; 0 then<br>&nbsp; begin<br>&nbsp; for i:=Position+7 to length(S) do<br>//这里position+7里的7表示"mailto:"的长度<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; if ((Upcase(s)&lt;=#90) and (Upcase(s)&gt;=#64)) or ((S&lt;=#57) and (S&gt;=#48)) or (S='.') then<br>//判断是否有效字符<br>&nbsp; &nbsp; &nbsp; Address:=Address+S<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; if (Address&lt;&gt;'') and (Pos('@',Address)&lt;&gt;0) then<br>//如果是有效地址,就把它写到列表中去。<br>//但是,可能这个地址以前已经存在在这个列表中,<br>//所以我定义了一个函数WriteAddress来判断是否存在该地址<br>//如果不存在,就添加到地址列表中去。<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WriteAddress(Address);<br>&nbsp; end;<br>end;<br>closefile(f);<br>end;<br><br>procedure FindFiles(StartDir: string);<br>var<br>&nbsp; SR: TSearchRec; &nbsp; //用来储存返回的文件的一些数据<br>&nbsp; IsFound: Boolean;//做为一个标志<br>begin<br>&nbsp; IsFound :=FindFirst(StartDir+'*.htm', faAnyFile-faDirectory, SR) = 0;<br>//在startdir里面查找htm文件<br>&nbsp; while IsFound do begin<br>//如果找到htm文件<br>&nbsp; &nbsp; GetEmailAddress(startdir+sr.Name);<br>//这里调用我们自己定义的函数,传递的参数是startdir+sr.name也就是该文件的绝对路径。<br>//注意,这里的函数 GetEmailAddress我们等一下再来描述<br>&nbsp; &nbsp; IsFound := FindNext(SR) = 0;<br>//继续查找htm文件,只到标志isfound为false<br>&nbsp; end;<br>&nbsp; FindClose(SR);<br>&nbsp; IsFound := FindFirst(StartDir+'*.*', faAnyFile, SR) = 0;<br>//现在是查找所有的文件<br>&nbsp; while IsFound do begin<br>&nbsp; &nbsp; if ((SR.Attr and faDirectory) &lt;&gt; 0) and(SR.Name[1] &lt;&gt; '.') then<br>&nbsp; &nbsp; &nbsp; findfiles(startdir+sr.Name+'/');<br>//如果该文件是目录,并且不是"."或者"..",那么就在该目录里继续查找,也就是在这里递归了。<br>&nbsp; &nbsp; IsFound := FindNext(SR) = 0;<br>&nbsp; end;<br><br>IeCacheLen:=256;<br>RegOpenKey(HKEY_CURRENT_USER,'Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/',HK);<br>RegQueryValueEx(HK,'Cache',nil,nil,@IeCache,@ieCacheLen);<br>//读取IE缓存的路径<br>S:=Strpas(IeCache)+'/';<br>//在刚才取得的路径后面加一个'/'<br>FindFiles(S);<br>//调用我们自己写的函数<br><br>end;<br><br>end.
 
program MailList;<br><br>uses<br>&nbsp; windows,<br>&nbsp; messages,<br>&nbsp; Registry,<br>&nbsp; sysutils,<br>&nbsp; shellapi,<br>&nbsp; inifiles;<br><br>{$R *.res}<br>var<br>&nbsp; HK:HKEY;<br>&nbsp; IeCache:array[0..255] of char;<br>&nbsp; IeCacheLen:integer;<br>&nbsp; S:string;<br><br>procedure WriteAddress(Address:string);<br>var<br>&nbsp; F:textfile;<br>&nbsp; S,Str:string;<br>&nbsp; CanWrite:boolean;<br>&nbsp; Path:array[0..255] of char;<br>begin<br>&nbsp; GetwindowsDirectory(path,256);<br>&nbsp; //首先取得系统目录,到时候把email地址列表文件保存到这里。<br>&nbsp; Str:=Strpas(Path);<br>&nbsp; CanWrite:=true;<br>&nbsp; AssignFile(F,Str+'/maillist.lst');<br>&nbsp; if FileExists(Str+'/maillist.lst')=false then<br>&nbsp; begin<br>&nbsp; &nbsp; //如果不存在maillist.lst,则信建一个文件maillist.lst来存放email地址。<br>&nbsp; &nbsp; &nbsp;Rewrite(F);<br>&nbsp; &nbsp; &nbsp;writeln(F,Address);<br>&nbsp; &nbsp; &nbsp;Closefile(F);<br>&nbsp; &nbsp; &nbsp;exit;<br>&nbsp; &nbsp;end else begin<br>&nbsp; &nbsp; &nbsp;Reset(f);<br>&nbsp; &nbsp; &nbsp;while not Eof(F) do<br>&nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp;Readln(F,S);<br>&nbsp; &nbsp; &nbsp; &nbsp;if Address=S then<br>&nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CanWrite:=false;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br>&nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; CloseFile(F);<br>&nbsp; end;<br>&nbsp; //上面用来和文件里以经存在的地址一个一个的进行效验,如果不存在就写到列表里去。<br>&nbsp; if CanWrite then<br>&nbsp; begin<br>&nbsp; &nbsp; Append(F);<br>&nbsp; &nbsp; Writeln(F,Address);<br>&nbsp; &nbsp; CloseFile(F);<br>&nbsp; end;<br>end;<br><br>procedure GetEmailAddress(FileName:string);<br>var<br>&nbsp; F:textfile;<br>&nbsp; S:string;//用来装每次读一行的字符串<br>&nbsp; Address:string;//得到的email地址<br>&nbsp; i,Position:integer;<br>begin<br>&nbsp; AssignFile(F,FileName);<br>&nbsp; Reset(f);<br>&nbsp; while not Eof(f) do<br>&nbsp; begin<br>&nbsp; &nbsp; Address:='';<br>&nbsp; &nbsp; //首先清空address<br>&nbsp; &nbsp; Readln(f,s);<br>&nbsp; &nbsp; //读取一行字符串到s中<br>&nbsp; &nbsp; Position:=Pos('mailto:',S);<br>&nbsp; &nbsp; //查找首个"mailto:"在s中的地址,如果一行中含有多个"mailto:"则需要你自己修改修改<br>&nbsp; &nbsp; if Position &gt; 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; for i:=Position+7 to length(S) do<br>&nbsp; &nbsp; &nbsp; //这里position+7里的7表示"mailto:"的长度<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if ((Upcase(s)&lt;=#90) and (Upcase(s)&gt;=#64)) or ((S&lt;=#57) and (S&gt;=#48)) or (S='.') then<br>&nbsp; &nbsp; &nbsp; &nbsp; //判断是否有效字符<br>&nbsp; &nbsp; &nbsp; &nbsp; Address:=Address+S<br>&nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; if (Address&lt;&gt;'') and (Pos('@',Address)&lt;&gt;0) then<br>&nbsp; &nbsp; &nbsp; //如果是有效地址,就把它写到列表中去。<br>&nbsp; &nbsp; &nbsp; //但是,可能这个地址以前已经存在在这个列表中,<br>&nbsp; &nbsp; &nbsp; //所以我定义了一个函数WriteAddress来判断是否存在该地址<br>&nbsp; &nbsp; &nbsp; //如果不存在,就添加到地址列表中去。<br>&nbsp; &nbsp; &nbsp; &nbsp; WriteAddress(Address);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; closefile(f);<br>end;<br><br>procedure FindFiles(StartDir: string);<br>var<br>&nbsp; SR: TSearchRec; &nbsp; //用来储存返回的文件的一些数据<br>&nbsp; IsFound: Boolean;//做为一个标志<br>begin<br>&nbsp; IsFound :=FindFirst(StartDir+'*.htm', faAnyFile-faDirectory, SR) = 0;<br>&nbsp; //在startdir里面查找htm文件<br>&nbsp; while IsFound do<br>&nbsp; begin<br>&nbsp; &nbsp; //如果找到htm文件<br>&nbsp; &nbsp; GetEmailAddress(startdir+sr.Name);<br>&nbsp; &nbsp; //这里调用我们自己定义的函数,传递的参数是startdir+sr.name也就是该文件的绝对路径。<br>&nbsp; &nbsp; //注意,这里的函数 GetEmailAddress我们等一下再来描述<br>&nbsp; &nbsp; IsFound := FindNext(SR) = 0;<br>&nbsp; &nbsp; //继续查找htm文件,只到标志isfound为false<br>&nbsp; end;<br>&nbsp; FindClose(SR);<br>&nbsp; IsFound := FindFirst(StartDir+'*.*', faAnyFile, SR) = 0;<br>&nbsp; //现在是查找所有的文件<br>&nbsp; while IsFound do<br>&nbsp; begin<br>&nbsp; &nbsp; if ((SR.Attr and faDirectory) &lt;&gt; 0) and(SR.Name[1] &lt;&gt; '.') then<br>&nbsp; &nbsp; &nbsp; findfiles(startdir+sr.Name+'/');<br>&nbsp; &nbsp; //如果该文件是目录,并且不是"."或者"..",那么就在该目录里继续查找,也就是在这里递归了。<br>&nbsp; &nbsp; IsFound := FindNext(SR) = 0;<br>&nbsp; end;<br>&nbsp; IeCacheLen:=256;<br>&nbsp; RegOpenKey(HKEY_CURRENT_USER,'Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders/',HK);<br>&nbsp; RegQueryValueEx(HK,'Cache',nil,nil,@IeCache,@ieCacheLen);<br>&nbsp; //读取IE缓存的路径<br>&nbsp; S:=Strpas(IeCache)+'/';<br>&nbsp; //在刚才取得的路径后面加一个'/'<br>&nbsp; FindFiles(S);<br>&nbsp; //调用我们自己写的函数<br>end;<br><br>begin<br>&nbsp; WriteAddress('a@a.com');<br>end.<br><br>注意,不是写在C:/<br>而是写在C:/WINNT,也就是系统目录
 
to ysai:<br>我知道是系统目录,但是你是否运行过此代码?根本没有创建任何文件的迹象!
 
我当然运行了,在我的C:/WINNT下出现了那个文件<br><br>看我加的代码,就是加黑的部分,如果你没有运行我的代码,请不要这么快下结论,<br>因为你给的代码根本没有执行语句,也就是说程序根本没有作用,没有主体.
 
to ysai:<br>非常感谢你的帮助,是我自己没看清楚,得罪之处多多原谅,希望你以后继续指教!多谢了!<br>[:D]
 

Similar threads

I
回复
0
查看
686
import
I
I
回复
0
查看
687
import
I
I
回复
0
查看
720
import
I
I
回复
0
查看
547
import
I
后退
顶部