解析语句
function SearchFile(mainpath:string;filename3,filename4:string; var foundresult:TStrings):Boolean;
var
filename,filename1,str,strk:string;
i,j,l:integer;
Found:Boolean;
subdir1:TStrings;
searchRec:TsearchRec;
// StringList: TStrings;
begin
if rightstr(mainpath,1)<>'\' then mainpath:=mainpath+'\';
found:=false;
filename3:='';
l:=length(form1.LabeledEdit3.Text);
if design<>1 then
begin
j:=strtoint(form1.LabeledEdit5.Text); //止
k:=strtoint(form1.LabeledEdit3.Text); //起
design:=1;
end;
if k<>j then
begin
strk:=inttostr(k);
while length(strk)<>l do
begin
strk:='0'+strk;
end;
filename3:=strk;
k:=k+1;
end;
subdir1:=TStringList.Create;
if (FindFirst(mainpath+'*.*', faDirectory,SearchRec)=0) then
begin
if ((SearchRec.Attr and faDirectory) = faDirectory) and (SearchRec.Name<>'.') and (SearchRec.Name<>'..') then
begin
subdir1.Add(SearchRec.Name);
end;
while (FindNext(SearchRec) = 0) do
begin
if ((SearchRec.Attr and faDirectory) = faDirectory) and (SearchRec.Name<>'.') and (SearchRec.Name<>'..') then //什么意思
begin
subdir1.Add(SearchRec.Name);
form1.memo1.Lines.Add(SearchRec.Name);
end;
end;
end;
FindClose(SearchRec);
str:='';
str:='*'+filename3+'*.jpg';
if (FindFirst(mainpath+str, faAnyFile-faDirectory, SearchRec)=0) then
begin
foundresult.Add(mainpath+SearchRec.Name);
while (FindNext(SearchRec) = 0) do //什么意思
begin
foundresult.Add(mainpath+SearchRec.Name);
end;
end;
FindClose(SearchRec);
for i:=0 to subdir1.Count-1 do
begin
found:=Searchfile(mainpath+subdir1.Strings[i]+'\',Filename,filename1,foundresult); //什么意思
end;
subdir1.Free;
form1.FileListBox1.Items.AddStrings(foundresult);
result:=found;
end;
大慨分开每个流程知道,但一综合整个流程就不清楚,请具体讲一讲流程
我的目的是输入001—010,就查找指定目录下是*001*.jpg--*010*.jpg的图片
结果只查到ad002ss.jpg图片, 再执行一次查到fd008a.jpg
c:\0\1\*001*.jpg--*010*.jpg
c:\0\2\*011*.jpg--*020*.jpg
问题点数:50、回复次数:6Top
1 楼zsy_good(只要坚定不移的走下去,那一定会成功)回复于 2002-05-18 10:13:04 得分 0
你写的查找文件的程序,怎么这样写阿
一般都是使用 findfirst findnext 等api 函数的呀
是要循环 判断 findnext 不为0就是真名有,然后把文件结构体的名字和
路径可以加进来,就可以拉Top
2 楼fshrq(我要有五粒星)回复于 2002-05-18 10:23:01 得分 0
我都是用findfirst findnext,你是怎样写?Top
3 楼Firec(Firec)回复于 2002-05-18 10:32:35 得分 0
多用API,没错的。Top
4 楼riddler(痛恨电脑)回复于 2002-05-22 09:40:54 得分 0
是啊Top
5 楼sleeepboy(阿闲)回复于 2002-05-25 09:18:33 得分 50
是这样的 这个函数先查找当前目录下的子目录
就是if ((SearchRec.Attr and faDirectory) = faDirectory) and (SearchRec.Name<>'.') and (SearchRec.Name<>'..') then 这一段
'.'和'..'分别表示当前目录和上层目录 然后查找当前目录下的所有符合条件的文件
最后调用Searchfile(mainpath+subdir1.Strings[i]'\',Filename,filename1,foundresult);来递归查找子目录下的文件
至于为什么查不全 还得再仔细看看 暂时没发现 hoho
by the way 你用Delphi6了啊 呵呵 有LabeledEdit的日子真是幸福
我还在用5呢Top
6 楼sleeepboy(阿闲)回复于 2002-05-25 09:28:42 得分 0
等等 再仔细看一遍以后 发现问题
你的流程是错误的 而且问题十分多啊
比如 这个函数的参数中有两个filename 原意应该是要查找的起始文件和中止文件 可是你的函数中 根本就没用到 而是从Edit中读取文件名 这样就失去递归函数的意义了
再者 你的k变量是全局变量 每次调用就加1 这样一次只能找到一个文件 而且在递归调用查找子目录的时候也会增加 这样如果有6个子目录 而且子目录中没有符合条件的文件 k的值就会跳跃 就会出现从2跳到8的情况Top
相关问题
- 有关SQL语句的解析
- 谁有SQL语句解析式控件或计算控件
- 关于SQL语句的解析问题。专家们看看。
- 请问javascript语句怎样解析url中的参数
- 帮我解析下这段SQL语句好吗?
- 帮我解析这句语句 if (j%2) continue
- 高分求人解析这段语句!!偶真的很菜~~啊
- 帮忙解析一下这个SQL语句~~~~特别是where后面的
- oracle语句中是否是大小写敏感的。oracle在解析select field from table和SELECT FIELD FROM TABLE 这两个语句时有区别吗?
- 在eclipse中,import org.apache.log4j.Logger;语句提示“不能解析导入”,请问该如何解决?




