我如何删除目录中的文件,排除[UninstallDelete]部分中该文件夹中的某些文件
问题描述:
我尝试通过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。文件。
答
我已经加解决了这个问题“[编号]”节到我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;