How to check if a directory exists, if there is a prompt to enter a new directory? I'm using innosetup to create an installer

4

I need to check if the C: \ SISAUTO, C: \ BASESISAUTO folder exists. If there are folders, create a new one for example C: \ SISAUTO2, C: \ BASESISAUTO2

Follow the code below.

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "SISAUTO - SISTEMA DE AUTOMAÇÃO COMERCIAL"
#define MyAppVersion "7.0.23"
#define MyAppPublisher "SUPPORT INFORMÁTICA"
#define MyAppURL "http://www.support-br.com.br"
#define MyAppExeName "MyProg.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{0D0A707B-5DF4-4AF9-BC4C-133886E5E379}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
CreateAppDir=no
OutputDir=C:\Users\SERVER\Desktop\Arquivos para Executavel\Output
OutputBaseFilename=INSTALADOR_SISAUTO_2017
SetupIconFile=C:\Users\SERVER\Desktop\Arquivos para Executavel\SISAUTO\install.ico
Compression=lzma
SolidCompression=yes

DisableWelcomePage=no
DisableDirPage=yes
DisableProgramGroupPage=yes
DisableReadyMemo=yes
DisableReadyPage=yes
DisableStartupPrompt=yes
DisableFinishedPage=no

[Languages]
Name: brazilianportuguese; MessagesFile: compiler:Languages\BrazilianPortuguese.isl

[Tasks]
Name: desktopicon; Description: Create a &desktop icon; GroupDescription: Additional icons:

[Dirs]
Name: C:\SISAUTO
Name: C:\BASESISAUTO
Name: C:\BASESISAUTO\GERNFE2
Name: C:\BASESISAUTO\BASE1
Name: C:\notas
Name: C:\ACBrMonitorPLUS
Name: C:\Unimake
Name: C:\Unimake\UniNFe
Name: C:\Unimake\UniDANFE

[Files]

Source: C:\Users\SERVER\Desktop\Arquivos para Executavel\BASESISAUTO\GERNFE2\*; DestDir: C:\BASESISAUTO\GERNFE2; Flags: recursesubdirs onlyifdoesntexist confirmoverwrite; Tasks: 
Source: C:\Users\SERVER\Desktop\Arquivos para Executavel\BASESISAUTO\BASE1\*; DestDir: C:\BASESISAUTO\BASE1; Flags: recursesubdirs onlyifdoesntexist confirmoverwrite
Source: C:\Users\SERVER\Desktop\Arquivos para Executavel\SISAUTO\*; DestDir: C:\SISAUTO; Flags: recursesubdirs onlyifdoesntexist confirmoverwrite
Source: C:\Users\SERVER\Desktop\Arquivos para Executavel\ACBrMonitorPLUS\*; DestDir: C:\ACBrMonitorPLUS; Flags: recursesubdirs onlyifdoesntexist confirmoverwrite; Tasks: ; Languages: 
Source: C:\Users\SERVER\Desktop\Arquivos para Executavel\UniNFe\*; DestDir: C:\Unimake\UniNFe; Flags: recursesubdirs onlyifdoesntexist confirmoverwrite
Source: C:\Users\SERVER\Desktop\Arquivos para Executavel\UniDANFE\*; DestDir: C:\Unimake\UniDANFE; Flags: recursesubdirs onlyifdoesntexist confirmoverwrite

[Icons]
Name: {userdesktop}\SISAUTO; Filename: C:\SISAUTO\sisauto.exe; Tasks: desktopicon
Name: {userdesktop}\GERNFE2; Filename: C:\BASESISAUTO\GERNFE2\gernfe2.exe; Tasks: desktopicon
Name: {userdesktop}\ACBrMonitorPLUS; Filename: C:\ACBrMonitorPLUS\ACBrMonitor.exe; Tasks: desktopicon
Name: {userdesktop}\UNINFE; Filename: C:\Unimake\UniNFe\uninfe.exe; Tasks: desktopicon
Name: {userdesktop}\UNIDANFE; Filename: C:\Unimake\UniDANFE\unidanfe.exe; Tasks: desktopicon

Name: {commonstartup}\GERNFE2; Filename: C:\BASESISAUTO\GERNFE2\gernfe2.exe
Name: {commonstartup}\ACBrMonitorPLUS; Filename: C:\ACBrMonitorPLUS\ACBrMonitor.exe
Name: {commonstartup}\UniNFe; Filename: C:\Unimake\UniNFe\uninfe.exe

[_ISTool]
UseAbsolutePaths=true
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Run]
Filename: C:\SISAUTO\InstalaDLL2.exe
Filename: C:\ACBrMonitorPLUS\ACBrMonitor.exe; Flags: nowait runminimized hidewizard runhidden
Filename: C:\Unimake\UniNFe\uninfe.exe; Flags: nowait runminimized hidewizard runhidden
    
asked by anonymous 28.02.2017 / 15:41

2 answers

5

Simple. You will place a [Code] tag. Then create a validation procedure. Now create a method to be fired before the installation: BeforeInstall. Inside the BeforeInstall you will call your validation methods.

Follow the example:

[Files]

Source: {#MyAppDirOut}\Exemplo.exe; DestDir: {#MyAppDirIns}; BeforeInstall: onBeforeInstall;

[Code]

procedure Validar();
begin
  if (DirExists('C:\SISAUTO')) then
    CreateDir('C:\SISAUTO2');
end;

procedure onBeforeInstall();
begin
  Validar;
end;

The methods you need are DirExists and CreateDir . To work with pascal code in inno setup, just put the [Code] tag.

My colleague's previous answer works, but only in Delphi, and I find it interesting that you edit your question too, why it's focused on inno setup.

    
01.03.2017 / 17:45
2

You can use System.SysUtils DirectoryExists and ForceDirectories to resolve your issue. For example:

if (DirectoryExists(C:\SISAUTO)) then
   ForceDirectories(C:\SISAUTO2);

Hope it helps. Hugs!

    
01.03.2017 / 17:18