微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

inno-setup – Pascal Scripting:检查dest目录是否为空,如果是,则只打印yes’/ no warning

我写了一个设置.在这个设置中没有任何反应,因为我只集中在一个领域:“
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

原文地址:https://www.jb51.cc/delphi/103000.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐