Я пытаюсь написать скрипт (новичок в pascal-script и innosetup). После установки он должен удалить все файлы в каталоге, кроме определенного имени файла.
[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;
Код должен удалить все файлы в повторяющейся директории, кроме setup-0.1.1.2.exe. так как я могу это сделать. Как будто теперь он ничего не удаляет.
[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;
Я изменил немного Inno Setup - Удалить всю папку приложения, кроме подкаталога данных , так как я просто хочу удалить файлы. Компилятор не жалуется ни на что, но я не понимаю, как упомянуть это конкретное имя файла здесь