天
天空之鹰
Unregistered / Unconfirmed
GUEST, unregistred user!
我写一个文件改名程序,文件一共分2类,I开头的,S开头的,这两类文件是一一对应的,也就是有I....就必须有S....(....是相同的,比如有I050101.02就应该有S050101.02);这个程序是批量改名的,也就是好多I、S文件一起改,但在改名之前我想检查一下I和S文件是不是一一对应,也就是文件完不完整,
有什么好方法?我先说说我的方法:
var//全局变量
a,b:string;
i:integer;
procedure TForm1.Button1Click(Sender: TObject);//在列表filelistbox2中列出以I开头或以S开头的文件名(取数量多的类型)
var
Attr:integer;
found:Boolean;
searchrec:Tsearchrec;
begin
filelistbox2.Clear;
b:=directorylistbox1.Directory;
a:=b+'/';
if FindFirst(a+'I05*.*',faAnyFile, SearchRec) = 0 then
begin
repeat
filelistbox2.items.Add(SearchRec.Name);
until (FindNext(SearchRec) <> 0);
end;
FindClose(SearchRec);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);//检测
var
v1,v2,vt,vs:string;
begin
b:=directorylistbox1.Directory;//文件夹路径
//在列表中列出以I开头或以S开头的文件名(取数量多的类型)
for i:=0 to filelistbox2.items.count-1 do//循环复制出文件名后面几位字符串
if filelistbox2.selected then
begin
vs:=filelistbox2.items;
v1:=copy(vs,2,7);
v2:=copy(vs,9,10);
vt:=Concat(v1,v2);
if
fileexists(b+'/'+'s'+vt)=false then//用查找函数查出文件夹中是否存在以S开头或I开头的文件
edit1.text:='no'//没有
else
edit1.text:='yes';//有
end;
这样有问题,我发现用fileexists函数检测时只检测列表最后一个文件是否存在,别的文件它都不检测。是不是fileexists函数不能动态查找?它的条件中不能有变量么?那怎么办,我目的是按下检测按钮就能查到每一个I开头的文件是否有一个S开头的文件和他共存。
有什么好方法?我先说说我的方法:
var//全局变量
a,b:string;
i:integer;
procedure TForm1.Button1Click(Sender: TObject);//在列表filelistbox2中列出以I开头或以S开头的文件名(取数量多的类型)
var
Attr:integer;
found:Boolean;
searchrec:Tsearchrec;
begin
filelistbox2.Clear;
b:=directorylistbox1.Directory;
a:=b+'/';
if FindFirst(a+'I05*.*',faAnyFile, SearchRec) = 0 then
begin
repeat
filelistbox2.items.Add(SearchRec.Name);
until (FindNext(SearchRec) <> 0);
end;
FindClose(SearchRec);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);//检测
var
v1,v2,vt,vs:string;
begin
b:=directorylistbox1.Directory;//文件夹路径
//在列表中列出以I开头或以S开头的文件名(取数量多的类型)
for i:=0 to filelistbox2.items.count-1 do//循环复制出文件名后面几位字符串
if filelistbox2.selected then
begin
vs:=filelistbox2.items;
v1:=copy(vs,2,7);
v2:=copy(vs,9,10);
vt:=Concat(v1,v2);
if
fileexists(b+'/'+'s'+vt)=false then//用查找函数查出文件夹中是否存在以S开头或I开头的文件
edit1.text:='no'//没有
else
edit1.text:='yes';//有
end;
这样有问题,我发现用fileexists函数检测时只检测列表最后一个文件是否存在,别的文件它都不检测。是不是fileexists函数不能动态查找?它的条件中不能有变量么?那怎么办,我目的是按下检测按钮就能查到每一个I开头的文件是否有一个S开头的文件和他共存。