Pascal脚本:检查dest目录是否为空,如果是,则仅显示“是"/“否"警告 [英] Pascal Scripting: Check if dest directory is empty and only print yes'/no warning if so

查看:89
本文介绍了Pascal脚本:检查dest目录是否为空,如果是,则仅显示“是"/“否"警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个设置.在此设置中,没有任何反应,因为我只专注于一个区域: wpSelectDir ",用户可以在其中选择安装程序应安装的目录.

I have written a setup. In this setup nothing happens, because I only concentrated on one area: The " wpSelectDir", where the user can choose a directory the setup should be installed in.

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

Now my code snippet should check, if ANYTHING exist in the chosen directory (any other folders, files, etc.). If so, the user gets warned if he still wants to continue, because everything in this directory will be removed then. If the user only created a new empty folder he should not get a warning, because nothing will be lost.

除了检查目录是否为空以外,我已经完成了代码片段(我用"如果1 = 1则"替换了该目录.)

I have the code snippet already finished excepting the check if the directory is empty (I replaced it with "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及其属性

I have already tried to use functions like "if FileExists( ...", but there I can not say " . " for any file. Also I was not successful using WizardDirValue and its properties.

如果有人可以帮助我或给我一个提示,我将不胜感激.

I would really appreciate if someone could help me or give me a hint.

非常感谢, 关于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

Note: This function also returns False if directory doesn't exists

这篇关于Pascal脚本:检查dest目录是否为空,如果是,则仅显示“是"/“否"警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆