Skip to content
⌘ NSIS Forum Archive

Deleting from temp folder (since 3.04)

7 posts

bnicer#

Deleting from temp folder (since 3.04)

Hi. I've been having a problem with a line of code since using Nsis 3.04. To clean up old installer files in the temp folder (Windows 10) during compile-time, I run:

!delfile $%TEMP%\nsi*.tmp
If there were no matching files/folders, this did nothing in the past. Now there is an error with the following log text:

!delfile: "C:\Users\TN\AppData\Local\Temp\nsi*.tmp" couldn't be deleted.
Error in script "F:\homepage\nsis\ansi\TIGsetup.nsi" on line 50 -- aborting creation process

Testing this a little further, I also noticed that folders, even when they exist, are not deleted -- same error log message -- and only files, not folders, if they exist, are deleted.

So either Windows 10 has changed the rules or my Windows configuration has changed or Nsis 3.04 is different. I could reinstall 3.03, because I have not actually checked it yet, but I am hoping someone has a better idea or way to fix the problem.

Thanks in advance.

edit: 3.03 shows same behavior without error log error, ie. possible to delete files but not folders from temp folder. I have no idea since when.
Anders#
3.04 is stricter in its error reporting but I don't think the way it deletes has changed.

!delfile is documented to "delete a file".

Use !delfile /nonfatal if you don't want to abort.

Use !tempfile to get a filename, don't use wildcards.
bnicer#
Thanks. The code is optional for me. I might remove it. The documentation merely states (as you said) that it deletes a file. Not a folder.

temp folders were treated as files once. It was a long time ago, when the folders were named nst*.tmp. My code still had the older naming. I posted this question with the newer naming.

I don't know about the !tempfile method. The idea was to clean out old installer files from failed installations, etc. -- when I tested a lot. There could be a whole bunch of those nst*.tmp files that got stuck. Any idea how to remove those in bulk (if the wildcard really is a wildcard) ? Thanks.
Anders#
You can get nst*.tmp folders in %temp% if the installer crashes. Normal usage should not leave them behind.

!system 'rmdir /S /Q "$%temp%\nst*.tmp"' might work.
bnicer#
No luck.

I created a folder nsm4235.tmp. And the !system syntax you suggested.

!system 'rmdir /S /Q "$%temp%\nsm*.tmp"'
The compiler throws a nonfatal error this time:

!system: "rmdir /S /Q "C:\Users\TN\AppData\Local\Temp\nsm*.tmp""
The filename, directory name, or volume label syntax is incorrect.
!system: returned 123

I think I will give up on it. Thank you for the suggestion and your help.
Anders#
I guess RMDir cannot handle wildcards, try this instead:

!ifdef NSIS_WIN32_MAKENSIS
!system 'for /D %A in ("$%temp%\ns*.tmp") do @RMDir /S /Q "%~A"'
!endif 
(RMDir /S /Q is obviously a bit risky and you might want to change RMDir to Echo before actually trying this just to see that it does not do something crazy)
bnicer#
That did the trick.

I used Echo first. I don't think it's too big a risk, if something untoward (and highly unlikely) were to happen. The files/folders in the Temp location could get wiped by accident, but are supposed to be expendable.

Great! Thanks. 🙂