加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

inno-setup – Pascal Scripting:检查dest目录是否为空,如果是,

发布时间:2020-12-15 10:06:35 所属栏目:大数据 来源:网络整理
导读:我写了一个设置.在这个设置中没有任何反应,因为我只集中在一个领域:“ wpSelectDir“,用户可以在其中选择应安装设置的目录. 现在我的代码片段应该检查,如果所选目录中存在ANYTHING(任何其他文件夹,文件等).如果是这样,如果用户仍想继续,则会收到警告,因为此
我写了一个设置.在这个设置中没有任何反应,因为我只集中在一个领域:“
wpSelectDir“,用户可以在其中选择应安装设置的目录.

现在我的代码片段应该检查,如果所选目录中存在ANYTHING(任何其他文件夹,文件等).如果是这样,如果用户仍想继续,则会收到警告,因为此目录中的所有内容都将被删除.
如果用户只创建了一个新的空文件夹,则不应该收到警告,因为什么都不会丢失.

我已经完成了代码片段,但检查目录是否为空(我将其替换为“if 1 = 1 then”).

请看看:

[Setup]
AppName=Testprogramm
AppVerName=Example
AppPublisher=Exxample
DefaultDirName={pf}C
DefaultGroupName=C
Compression=lzma
SolidCompression=yes

[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
begin
   if CurPageID = wpSelectDir then // if user is clicked the NEXT button ON the select directory window; if1 begins here;
   begin
   if 1=1 then // if the directory is not empty; thx 4 help stackoverflow
   begin // warning with yes and no
    if MsgBox('The file contains data. This data will be removed permanently by continuing the setup?',mbConfirmation,MB_YESNO) = IDYES then //if 3 begins here
    begin
      Result := True;
    end
    else
    begin
      Result := False;
    end;
    end; // if2 ends here
  end // not CurPageID but any other begins here
  else
  begin
      Result := True;
  end; 
end;

我已经尝试使用像“if FileExists(…”这样的函数,但我不能说“.”任何文件.我也没有成功使用WizardDirValue及其属性.

如果有人可以帮助我或给我一些提示,我将非常感激.

非常感谢,
问候C.

解决方法

使用FindFirst / FindNext.

例:

function isEmptyDir(dirName: String): Boolean;
var
  FindRec: TFindRec;
  FileCount: Integer;
begin
  Result := False;
  if FindFirst(dirName+'*',FindRec) then begin
    try
      repeat
        if (FindRec.Name <> '.') and (FindRec.Name <> '..') then begin
          FileCount := 1;
          break;
        end;
      until not FindNext(FindRec);
    finally
      FindClose(FindRec);
      if FileCount = 0 then Result := True;
    end;
  end;
end;

注意:如果目录不存在,此函数也返回False

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读