如何删除目录中的文件,在 [Uninstall Delete] 部分排除此目录中的某些文件

How can i delete files in directory, exclude some files in this derectory in [UninstallDelete] section

我试着用Ant的例子在InnoSetup中写一个脚本。

    <delete includeemptydirs="true">
        <fileset dir="${term.path}/configuration" excludes="*.rtf,*.property,accounts/**/*,log/*,**/*.p12"/>
    </delete>

但我不明白如何通过命名模式删除目录排除文件中的文件:

*.rtf,*.property,accounts/**/*,log/*,**/*.p12

"。我没有在帮助文件的 Inno Setup 的 [InstallDelete] 部分中找到排除参数。

我已经通过将“[代码]”部分添加到我的 inno 脚本中解决了这个问题。我确信我的问题可以以更紧凑和更好的方式解决。

[Code]

//Procedure checks whether the file extension 
//specified values or not. In the case of non-compliance,
//the file is deleted
procedure CompareAndRemove(const Path: String); 
begin 
    if (ExtractFileExt(Path) <> '.rtf') 
        and (ExtractFileExt(Path) <> '.p12')
        and (ExtractFileExt(Path) <> '.property')
        then  DelayDeleteFile(Path, 2);    
end; 

// Procedure compare Path of folder with given paths 
procedure CompareImportantFolders(const PathToCompare: String; const Path: String );
begin 
     if  (PathToCompare <> Path+'.') 
        and (PathToCompare <> Path+'..')
     then  DelTree(PathToCompare, True, True, True);
end;                       


// Procedure check a folder to important files inside
function isImportantFilesExist(Path: String): Boolean;
var
  FindRec: TFindRec;
begin
  if FindFirst(ExpandConstant(Path + '*'), FindRec) then
  begin 
    try
      repeat
        // If just file
      if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0         
        then
         begin 
             if ExtractFileExt(Path+FindRec.Name) = '.p12'
             then  
             Result := true;
         end;
      until not FindNext(FindRec);
    finally
      FindClose(FindRec);
    end; 
    end; 
   end;   


//Procedure runs on folder's first level and deletes all files exclude
// files with special ext. (look at procedure "CompareAndRemove")
procedure CleanDirOutOfFiles(const Path: String);
var  
  FindRec: TFindRec;
begin
  if FindFirst(ExpandConstant(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;




// Procedure runs in folder and delete all folders include 
// itself
procedure CleanDirOutOfFolders(const Path: String);
var
  FilesFound: Integer;
  DirFound: Integer;
  FindRec: TFindRec;
begin //(1)
  if FindFirst(Path + '*', FindRec) then
  begin //(2)
    try
      repeat
        // If found file - Directory
      if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 16         
        then
         begin    
          CompareImportantFolders(Path+FindRec.Name, Path)
         end; 
      until not FindNext(FindRec);
    finally
      FindClose(FindRec);
    end;
    end;
   end;

// Procedure clean folder out of unimportant 
// files and directories
procedure CleanDir(const Path: String);
var
  FilesFound: Integer;
  DirFound: Integer;
  FindRec: TFindRec;
begin //(1)
  FilesFound := 0;
  DirFound  := 0;
  if FindFirst(ExpandConstant(Path + '*'), FindRec) then
  begin //(2)
    try
      repeat
        // If found file - file
      if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 0         
        then 
         begin
        CompareAndRemove(Path+FindRec.Name);
         end
      // If found file - directory
       else 
           begin
          if  (Path+FindRec.Name <> Path+'.') 
          and (Path+FindRec.Name <> Path+'..')
          and (Path+FindRec.Name <> Path+'log')
          and (Path+FindRec.Name <> Path+'accounts')
          then 
              begin  
                  CleanDirOutOfFolders(Path+FindRec.Name+'\'); 
                  CleanDirOutOfFiles(Path+FindRec.Name+'\');
                      if not isImportantFilesExist(Path+FindRec.Name+'\')
                      then
                          begin
                            DelTree(Path+FindRec.Name, True, True, True);
                          end;
              end;
          end;                   
      until not FindNext(FindRec);
    finally
      FindClose(FindRec);
    end;
    end;
   end;