I am trying to write a script(am new to pascal-script and innosetup), Post installation it has to delete all the files in a directory excluding a specific file name.
[Code]
procedure CompareAndRemove(const Path: String);
begin
Log('checking file path : ' + Path);
if (ExtractFileExt(Path) <> 'setup-0.1.1.2.exe')
then DelayDeleteFile(Path, 2);
end;
procedure CleanDirOutOfFiles();
var
Path, FilePath: string;
FindRec: TFindRec;
begin
Path := ExpandConstant('{{app}\{#test}\recurring}');
if FindFirst(Path + '*', FindRec) then
begin
try
repeat
// if just File
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0
then
begin
CompareAndRemove(Path+FindRec.Name);
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end;
end;
The code has to delete all the files in the recurring directory except setup-0.1.1.2.exe. so how can I do this. As if now it is not deleting anything.
[Code]
procedure DelTreeExceptSavesDir(Path: string);
var
FindRec: TFindRec;
FilePath: string;
begin
if FindFirst(Path + '\*', FindRec) then
begin
try
repeat
if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
begin
FilePath := Path + '\' + FindRec.Name;
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0 then
begin
if DeleteFile(FilePath) then
begin
Log(Format('Deleted file %s', [FilePath]));
end
else
begin
Log(Format('Failed to delete file %s', [FilePath]));
end;
end
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end
else
begin
Log(Format('Failed to list %s', [Path]));
end;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
SavePath: string;
begin
SavePath := ExpandConstant('{app}\{#test}\recurring');
if CurUninstallStep = usUninstall then
begin
DelTreeExceptSavesDir(SavePath);
end;
end;
I have modified a bit Inno Setup - Delete whole application folder except for data subdirectory since i just want to delete files. Compiler is not complaining anything but I am not getting how to mention that specific file name here