回 帖 发 新 帖 刷新版面

主题:求一句搞定

想检查某盘的根目录下有没有*.INI文件,怎么写代码!!!

回复列表 (共3个回复)

沙发

FindFirst

板凳

想知道在D盘有没有*.INI,如果有就程序继续,如果没有就创建,代码如何写

3 楼

procedure findall(diskpath: String; var fileresult: Tstrings);
var
fpath,s: String;
fs: TsearchRec;
begin
 fpath:=diskpath+'\*.*';
 if FindFirst(fpath,faAnyFile,fs)=0 then
   begin
   if (fs.Name<>'.')and(fs.Name<>'..') then
     if (fs.Attr and faDirectory)=faDirectory then
         findall(diskpath+'\'+fs.Name,fileresult)
       else if (ExtractFileExt(fs.Name)='.ini') then
          fileresult.add(diskpath+'\'+fs.Name);
     while findnext(fs)=0 do
       begin
       if (fs.Name<>'.')and(fs.Name<>'..') then
         if (fs.Attr and faDirectory)=faDirectory then
             Findall(diskpath+'\'+fs.Name,fileresult)
         else if (ExtractFileExt(fs.Name)='.ini') then
          fileresult.add(diskpath+'\'+fs.Name);
       end;
   end;
 Findclose(fs);
end;
效率可能不是很好,希望能看到更好的答案

我来回复

您尚未登录,请登录后再回复。点此登录或注册