Inno setup 如何删除目录中的文件,在[UninstallDelete]部分排除此目录中的某些文件
我试图通过Ant的例子在InnoSetup中编写一个脚本Inno setup 如何删除目录中的文件,在[UninstallDelete]部分排除此目录中的某些文件,inno-setup,Inno Setup,我试图通过Ant的例子在InnoSetup中编写一个脚本 <delete includeemptydirs="true"> <fileset dir="${term.path}/configuration" excludes="*.rtf,*.property,accounts/**/*,log/*,**/*.p12"/> </delete> “。我在帮助文件中的Inno安装程序的[InstallDelete]部分中没有找到排
<delete includeemptydirs="true">
<fileset dir="${term.path}/configuration" excludes="*.rtf,*.property,accounts/**/*,log/*,**/*.p12"/>
</delete>
“。我在帮助文件中的Inno安装程序的[InstallDelete]部分中没有找到排除参数。我通过在Inno脚本中添加“[Code]”部分解决了这个问题。我确信我的问题可以以更紧凑、更好的方式解决
[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;
[代码]
//过程检查文件扩展名是否正确
//是否指定值。如果不符合要求,
//该文件已被删除
过程CompareAndRemove(常量路径:字符串);
开始
if(ExtractFileExt(路径)'.rtf')
和(ExtractFileExt(路径)'.p12')
和(ExtractFileExt(路径)'.property')
然后延迟删除文件(路径2);
结束;
//过程将文件夹的路径与给定路径进行比较
过程比较端口文件夹(常量路径比较:字符串;常量路径:字符串);
开始
if(路径比较路径+'。)
和(PathToCompare路径+“…”)
然后是DelTree(PathToCompare,True,True,True);
结束;
//程序检查文件夹中的重要文件
函数IsImportantFileSexList(路径:字符串):布尔值;
变量
FindRec:TFindRec;
开始
如果FindFirst(ExpandConstant(Path+'*'),FindRec),则
开始
尝试
重复
//如果只是文件
如果FindRec.Attributes和文件属性目录=0
然后
开始
如果ExtractFileExt(Path+FindRec.Name)='.p12'
然后
结果:=真;
结束;
直到没有FindNext(FindRec);
最后
FindClose(FindRec);
结束;
结束;
结束;
//过程在文件夹的第一级上运行,并删除所有文件
//具有特殊ext的文件(请参阅“CompareAndRemove”过程)
过程CleanDiroOutOffiles(常量路径:字符串);
变量
FindRec:TFindRec;
开始
如果FindFirst(ExpandConstant(Path+'*'),FindRec),则
开始
尝试
重复
//如果只是文件
如果FindRec.Attributes和文件属性目录=0
然后
开始
比较数据移动(路径+FindRec.Name);
结束;
直到没有FindNext(FindRec);
最后
FindClose(FindRec);
结束;
结束;
结束;
//过程在文件夹中运行并删除所有文件夹,包括
//本身
过程CleanDirOutOfFolders(常量路径:字符串);
变量
找到的文件:整数;
DirFound:整数;
FindRec:TFindRec;
开始//(1)
如果FindFirst(路径+'*',FindRec),则
开始//(2)
尝试
重复
//如果找到文件-目录
如果FindRec.Attributes和文件属性目录=16
然后
开始
CompareImportFolders(Path+FindRec.Name,Path)
结束;
直到没有FindNext(FindRec);
最后
FindClose(FindRec);
结束;
结束;
结束;
//清除文件夹的过程不重要
//文件和目录
过程CleanDir(常量路径:字符串);
变量
找到的文件:整数;
DirFound:整数;
FindRec:TFindRec;
开始//(1)
找到的文件:=0;
DirFound:=0;
如果FindFirst(ExpandConstant(Path+'*'),FindRec),则
开始//(2)
尝试
重复
//如果找到文件-文件
如果FindRec.Attributes和文件属性目录=0
然后
开始
比较数据移动(路径+FindRec.Name);
结束
//如果找到文件-目录
其他的
开始
如果(路径+FindRec.Name路径+'。)
和(Path+FindRec.Name Path+'..')
和(Path+FindRec.Name Path+'log')
和(Path+FindRec.Name Path+‘accounts’)
然后
开始
CleanDirOutOfFolders(Path+FindRec.Name+'\');
CleanDiroOutOffiles(Path+FindRec.Name+'\');
如果不是,则为重要文件性别列表(路径+FindRec.Name+'\')
然后
开始
DelTree(Path+FindRec.Name,True,True);
结束;
结束;
结束;
直到没有FindNext(FindRec);
最后
FindClose(FindRec);
结束;
结束;
结束;
[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;