如何删除目录中的文件,在[UninstallDelete]部分中排除此derectory中的一些文件

时间:2015-07-21 10:42:54

标签: inno-setup

我试图通过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] sectoin中找到排除参数。

1 个答案:

答案 0 :(得分:1)

我通过添加&#34; [代码]&#34;解决了这个问题。部分到我的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;