在临时文件夹中创建文件夹

Creating A Folder In the Temp Folder

我正在尝试在没有随机名称的临时文件夹中创建一个文件夹。

这是我尝试在临时文件夹中创建文件夹的方式。

if not DirExists(ExpandConstant('{%tmp}\Utilities\SDK')) then
    CreateDir(ExpandConstant('{%tmp}\Utilities\SDK'));
    Log('Temp\Utilities\SDK Folder Has Been Created.');

我查看了 this 线程,但不幸的是,即使使用 %,它仍然没有创建文件夹。

脚本按预期编译和运行,但是该文件夹不会创建,即使它说它在日志文件中,

我知道日志文件会这样说,因为它也被告知,但是,如果无法创建文件夹,它不会崩溃吗?或者 return 如果存在 if 语句则为 false?

我认为您需要 Windows 温度而不是 Inno Setup

中的 tmp

{tmp}: Temporary directory used by Setup or Uninstall. This is not the value of the user's TEMP environment variable. It is a subdirectory of the user's temporary directory which is created by Setup or Uninstall at startup (with a name like "C:\WINDOWS\TEMP\IS-xxxxx.tmp"). All files and subdirectories in this directory are deleted when Setup or Uninstall exits. During Setup, this is primarily useful for extracting files that are to be executed in the [Run] section but aren't needed after the installation.

所以我认为你想做这样的事情:

if not DirExists(ExpandConstant('{%temp}\Utilities\SDK')) then
   CreateDir(ExpandConstant('{%temp}\Utilities\SDK'));
   Log('Temp\Utilities\SDK Folder Has Been Created.');

使用 CreateDir() 您必须一个接一个地创建目录,而不是一次创建一个目录结构。

if not DirExists(ExpandConstant('{tmp}\Utilities')) then
  CreateDir(ExpandConstant('{tmp}\Utilities'));
if not DirExists(ExpandConstant('{tmp}\Utilities\SDK')) then
  CreateDir(ExpandConstant('{tmp}\Utilities\SDK'));

if DirExists(ExpandConstant('{tmp}\Utilities\SDK')) then
   Log('Temp\Utilities\SDK Folder Has Been Created.') else
   Log('Temp\Utilities\SDK Folder ERROR : NOT Created.');

Inno Setup 具有一次创建目录结构的功能
function ForceDirectories(Dir: string): Boolean;

示例:

if not DirExists(ExpandConstant('{tmp}\Utilities\SDK')) then
   ForceDirectories(ExpandConstant('{tmp}\Utilities\SDK'));

另请注意:

  • {tmp} 都与 Inno Setup Temp 文件夹有关 is-XXXXX.tmp
    C:\用户\...\AppData\Local\Temp\is-XXXXX.tmp
  • {%temp} 是用户的临时文件夹
    C:\用户\...\AppData\Local\Temp