Pascal Scripting: Check if dest directory is empty and only print yes'/no warning if so

后端 未结 1 1080
孤独总比滥情好
孤独总比滥情好 2020-12-17 05:03

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

相关标签:
1条回答
  • 2020-12-17 05:46

    Use FindFirst/FindNext.

    Example:

    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;
    

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

    0 讨论(0)
提交回复
热议问题