2015-07-21 171 views
3

我嘗試通過Ant的示例在InnoSetup中編寫腳本。我如何刪除目錄中的文件,排除[UninstallDelete]部分中該文件夾中的某些文件

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

但我不明白我怎麼可以在目錄中刪除文件的命名模式排除文件:

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

」我沒有發現排除在創新安裝的[InstallDelete]參數幫助sectoin。文件。

回答

1

我已經加解決了這個問題「[編號]」節到我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; 
相關問題