0

I am a beginner in Pascal coding and Innosetup. Would like to request some advice on how to use the procedure to execute a delete folder and transfer folder operation.

I was trying to move files from the release folder in 'C:\Program Files (x86)\winpxe1\Apache24\htdocs\current\Storygame*' to the current folder instead. 'C:\Program Files (x86)\winpxe1\Apache24\htdocs\current\" Next, I wanted to delete another release folder of the same name in 'C:\Program Files (x86)\winpxe1\Apache24\Storygame'.

The following is an extract of my code:

[Tasks]

Name: "desktopicon";                                       Description: "{cm:CreateDesktopIcon}";GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked 

[Files]
 Source: "C:\Program Files (x86)\Inno Setup 5\Examples\MyProg.exe";             
 DestDir: "{app}"; Flags: ignoreversion

[Run] 
 Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,    {#StringChange(MyAppName, '&', '&&')}}";AfterInstall: DirectoryCopy     DeleteTransferFolder Flags: nowait postinstall skipifsilent       

[Code]

procedure DirectoryCopy(SourcePath, DestPath: string);

  var

 FindRec: TFindRec;
 SourceFilePath: string;
 DestFilePath: string;
 begin
  if FindFirst(SourcePath + '\*', FindRec) then     
  begin     
   try      
    repeat       
  if (FindRec.Name <> '.') and (FindRec.Name <> '..')   then
     begin
         SourceFilePath := SourcePath + '\' + FindRec.Name;

          DestFilePath := DestPath + '\' + FindRec.Name;

            if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then


begin

if FileCopy(SourceFilePath, DestFilePath, False) then
begin
           Log(Format('Copied %s to %s', [SourceFilePath, DestFilePath]));
         end
           else
         begin
           Log(Format('Failed to copy %s to %s', [SourceFilePath,          DestFilePath]));
         end;
       end
         else
       begin
         if DirExists(DestFilePath) or CreateDir(DestFilePath) then
         begin                                                                                    Log(Format('Created %s', [DestFilePath]));
           DirectoryCopy(SourceFilePath, DestFilePath);
         end
           else
         begin
           Log(Format('Failed to create %s', [DestFilePath]));
         end;
       end;
     end;
   until not FindNext(FindRec);
 finally
   FindClose(FindRec);
 end;
end
  else
 begin
     Log(Format('Failed to list %s', [SourcePath]));
   end;
  end;

    procedure DirectoryCopy(SourcePath, DestPath: string);
    begin      
    Result := DirectoryCopy( 'C:\Program Files (x86)\winpxe1\Apache24      \htdocs\current\Storygame\*','C:\Program Files (x86)\winpxe1\Apache24\htdocs\current': string);                        
end;
  procedure DeleteTransferFolder();
   begin
   MsgBox('DeleteTransferFolder 1', mbInformation, MB_OK);

   if (FileExists (ExpandConstant( 'C:\Program Files (x86)\winpxe1\Apache24    \Storygame'))) then
   begin      DelTree(ExpandConstant('C:\Program Files (x86)\winpxe1    \Apache24    \Storygame'), True, True, True);

   MsgBox('DeleteTransferFolder 2', mbInformation, MB_OK);    end;

After running this script, I encountered the "Compiler error": "Directive or Parameter "AfterInstall" expression error: Invalid token "DeleteTransferFolder" found."

I would like to also give credit to the authors of the original code for the directorycopy and deletetransferfolder as it was extracted from other questions in this forum. Any advice appreciated on how I can integrate these codes with the existing support class references of innosetup. Regards

Rudy Velthuis
  • 28,387
  • 5
  • 46
  • 94
  • You better show us a link where you got this code. That `Run` section does not look properly formatted. Specifically, the `AfterInstall` portion which is causing you issues. I'm pretty sure it expects just one or the other, but not both. I'm also pretty sure it needs a semicolon `;` before `Flags`. – Jerry Dodge Feb 26 '18 at 12:09
  • Hi there, the links are the following: For copy/transfer folder-- https://stackoverflow.com/questions/33391915/inno-setup-copy-folder-subfolders-and-files-recursively-in-code-section For delete folders- https://stackoverflow.com/questions/14344889/cant-get-deltree-to-delete-a-folder-in-inno-setup – MightStackier Feb 27 '18 at 02:16
  • Regarding the AfterInstall portion, How about a 2nd line of code for this [Run] section since both procedures cannot be called together? – MightStackier Feb 27 '18 at 03:42

0 Answers0