在安装新软件之前删除整个目录

问题描述 投票:0回答:1

我使用 Inno Setup 创建了一个简单的代码,我只想在安装新文件和程序之前自动删除“SPMPET”目录中的原始文件。但是我写的代码并没有删除文件,而是保留在那里。

[Code]
procedure Deleting;
begin
  // Delete the directory C:\Localdata\SPMPET and everything inside it
  DelTree(('C:\Localdata\SPMPET'), True, True, True);
end;

我的代码有什么问题?

inno-setup pascal
1个回答
0
投票
Your code looks correct, but it's possible that the directory or files inside it are being used by another process, and that's why they can't be deleted. You can try the following steps:

Close all programs that may be using files in the "SPMPET" directory.
Add a try..except block around the DelTree function to catch any exceptions that may be thrown during the deletion process. This will allow you to see any errors that may be occurring.

[Code]
procedure Deleting;
begin
try
// Delete the directory C:\Localdata\SPMPET and everything inside it
DelTree('C:\Localdata\SPMPET', True, True, True);
except
MsgBox('Error deleting directory', mbError, MB_OK);
end;
end;

If the directory or files inside it are still not being deleted, probably something else wrong with your code 
© www.soinside.com 2019 - 2024. All rights reserved.