找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 4261|回复: 0

[开源] 【开源】遍历目录或文件(delphi7)

[复制链接]

1214

主题

352

回帖

11

精华

管理员

菜鸟

积分
93755

贡献奖关注奖人气王精英奖乐于助人勋章

发表于 2009-7-26 11:57:43 | 显示全部楼层 |阅读模式
<table style="TABLE-LAYOUT: fixed">
<tbody>
<tr>
<td>
<div id="blog_text" class="cnt">unit Unit1; <br/><br/>interface <br/><br/>{$WARN UNIT_PLATform OFF}<br/>uses<br/>Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, forms,<br/>Dialogs, StdCtrls, FileCtrl; <br/><br/>type<br/>Tform1 = class(Tform)<br/>Button1: TButton;<br/>Memo1: TMemo;<br/>Edit1: TEdit;<br/>Button2: TButton;<br/>Memo2: TMemo;<br/>Edit2: TEdit;<br/>procedure Button1Click(Sender: TObject);<br/>procedure Button2Click(Sender: TObject);<br/>procedure Memo1DblClick(Sender: TObject);<br/>private<br/>{ Private declarations }<br/>public<br/>{ Public declarations }<br/>end; <br/><br/>var<br/>form1: Tform1;<br/>sDIR:string; <br/><br/>implementation <br/><br/>{$R *.dfm}<br/>// 放两个button,两个Edit,两个memo控件到form 上<br/>procedure SCanDir(objDir:string;dirList:TStrings);<br/>var<br/>sr:TSearchRec;<br/>begin<br/>dirList.Clear;<br/>if FindFirst(objDir, faDirectory, sr) = 0 then<br/>begin<br/>repeat<br/>if (sr.Attr and faDirectory) = faDirectory then<br/>begin<br/>if (sr.Name='.') or (sr.Name='..') then continue;<br/>dirList.Add(sr.Name);<br/>end;<br/>until FindNext(sr) &lt;&gt; 0;<br/>FindClose(sr);<br/>end; <br/><br/>end; <br/><br/>procedure SCanFile(objfile:string;fileList:TStrings);<br/>var<br/>sr:TSearchRec;<br/>begin<br/>fileList.Clear;<br/>if FindFirst(objFile, faAnyFile, sr) = 0 then<br/>begin<br/>repeat<br/>fileList.Add(sr.Name);<br/>until FindNext(sr) &lt;&gt; 0;<br/>FindClose(sr);<br/>end; <br/><br/>end; <br/><br/>procedure Tform1.Button1Click(Sender: TObject);<br/>begin<br/>if SelectDirectory('选择目录',sDIR,sDIR) then<br/>edit1.text:=sDIR;<br/>end; <br/><br/>procedure Tform1.Button2Click(Sender: TObject);<br/>begin<br/>SCanDir(sDIR+'\????????',Memo1.lines);<br/>end; <br/><br/>procedure Tform1.Memo1DblClick(Sender: TObject);<br/>var<br/>nLine:integer;<br/>ss:string;<br/>begin<br/>nLine:=memo1.Perform(EM_LINEFROMCHAR,memo1.SelStart,0);<br/>edit2.Text :=inttostr(nLine);<br/>ss:= memo1.Lines[nLine];<br/>memo2.Clear;<br/>if ss &lt;&gt; '' then<br/>SCanFile(sDIR+'\'+ss+'\*.txt',Memo2.Lines); <br/><br/>end; <br/><br/>end.</div></td></tr></tbody></table>
【VB】QQ群:1422505加的请打上VB好友
【易语言】QQ群:9531809  或 177048
【FOXPRO】QQ群:6580324  或 33659603
【C/C++/VC】QQ群:3777552
【NiceBasic】QQ群:3703755
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表