traveler3468
traveler3468

Reputation: 1656

Creating A Folder In the Temp Folder

I'm trying to create a folder within the temp folder that doesn't have a random name.

Here is how I was trying to create the folder within the temp folder.

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

I had a look at this thread, but even with the %, unfortunately, it still doesn't create the folder.

The script compiles and runs as expected, however the folder doesn't create even though it says it has in the log file,

I understand that the log file will say that because its told too, however, if the folder was unable to be created, wouldnt it crash? or return a false if an if statement was present?

Upvotes: 4

Views: 1938

Answers (2)

moskito-x
moskito-x

Reputation: 11968

With CreateDir() You must create dirs one after the other and not a dir structure at once.

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 has a function to create a dir structure at once
function ForceDirectories(Dir: string): Boolean;

Example:

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

Also keep in mind :

  • {tmp} all is related to the Inno Setup Temp folder is-XXXXX.tmp
    C:\Users\...\AppData\Local\Temp\is-XXXXX.tmp
  • {%temp} is the users Temp folder
    C:\Users\...\AppData\Local\Temp

Upvotes: 5

S.Spieker
S.Spieker

Reputation: 7365

I think you want the Windows Temp and not the tmp from InnoSetup

{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.

So I think you want to do somethink like this:

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

Upvotes: 0

Related Questions