I've just found a rogue directory being left behind by one of my dev tests, so in the next release I'd like to handle it automatically where it already exists on a users PC (plus it is about time I got my head around some NSIS).
The folder in question is %LOCALAPPDATA%\cache\picard
, so I need to delete the picard folder if it exists (this I can do), then delete the cache dir if it is now empty (this I am stuck on).
The code so far:
!macro CustomCodePreInstall
${If} ${FileExists} "$LOCALAPPDATA\cache\picard\*.*"
RMDir /r "$LOCALAPPDATA\cache\picard"
${If} ${FileExists} "$LOCALAPPDATA\cache\*.*"
MessageBox MB_OK "'$LOCALAPPDATA\cache\*.*' exists"
${If} ${FileExists} "$LOCALAPPDATA\cache"
MessageBox MB_OK "'$LOCALAPPDATA\cache' exists"
${EndIf}
${EndIf}
${EndIf}
!macroend
Running this the picard folder is deleted, but the checks for the cache folder (with and without *.*) both prove truthy, despite that the folder is definitely now empty.
So is there a predefined way to check if a directory is empty, or otherwise how could I include a function such as DirState in my code?
Thanks, too easy.
Considering I'm familiar with rmdir and what the /r switch does (or some version of them) on just about every command line I've ever used (plus I used it in my code above) I guess I feel kinda stupid for over-thinking this.
Once again thank you.