Inno Setup - Check if multiple folders exist

匿名 (未验证) 提交于 2019-12-03 10:10:24

问题:

I have a custom uninstall page, which is invoked with this line:

UninstallProgressForm.InnerNotebook.ActivePage := UninstallConfigsPage; 

Now, this just shows the page every time the uninstaller is run, but I need it to show only if certain folders exist (there's 6 of them). I could make an if statement with a bunch of or's, but I'm wondering if there's a neater way to do it.

回答1:

In general, there's no better way than calling DirExists for each folder:

if DirExists('C:\path1') or    DirExists('C:\path2') or    DirExists('C:\path3') then begin   { ... } end; 

Though, when processing a set of files/folders, it's advisable to have their list stored in some container (like TStringList or array of string), to allow their (repeated) bulk-processing. You already have that (Dirs: TStringList) from my solution to your other question.

var   Dirs: TStringList; begin   Dirs := TStringList.Create();   Dirs.Add('C:\path1');   Dirs.Add('C:\path2');   Dirs.Add('C:\path2'); end; 
function AnyDirExists(Dirs: TStringList): Boolean; var   I: Integer; begin   for I := 0 to Dirs.Count - 1 do   begin     if DirExists(Dirs[I]) then     begin       Result := True;       Exit;     end;   end;    Result := False; end; 

But I know from your other question, that you map all the paths to checkboxes. Hence, all you need to do, is to check, if there's any checkbox:

if CheckListBox.Items.Count > 0 then begin   UninstallProgressForm.InnerNotebook.ActivePage := UninstallConfigssPage;    { ... }    if UninstallProgressForm.ShowModal = mrCancel then Abort;    { ... }    UninstallProgressForm.InnerNotebook.ActivePage := UninstallProgressForm.InstallingPage; end; 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!