Pascal Scripting:检查dest目录是否为空,如果是,则仅打印yes'/ no warning

use*_*760 4 inno-setup

我写了一个设置.在这个设置中没有任何反应,因为我只集中在一个区域:" 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;
Run Code Online (Sandbox Code Playgroud)

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

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

非常感谢,问候C.

小智 6

使用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;
Run Code Online (Sandbox Code Playgroud)

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