Old 17th January 2019, 10:18   #1
bnicer
Senior Member
 
Join Date: Feb 2005
Location: London
Posts: 218
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:

code:
!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.
bnicer is offline   Reply With Quote
Old 17th January 2019, 12:06   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,980
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 17th January 2019, 17:20   #3
bnicer
Senior Member
 
Join Date: Feb 2005
Location: London
Posts: 218
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.
bnicer is offline   Reply With Quote
Old 17th January 2019, 17:51   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,980
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 17th January 2019, 18:27   #5
bnicer
Senior Member
 
Join Date: Feb 2005
Location: London
Posts: 218
No luck.

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

code:
!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.
bnicer is offline   Reply With Quote
Old 17th January 2019, 18:58   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,980
I guess RMDir cannot handle wildcards, try this instead:

PHP Code:
!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)

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 17th January 2019, 19:40   #7
bnicer
Senior Member
 
Join Date: Feb 2005
Location: London
Posts: 218
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.
bnicer is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump