Search code examples
nsis

NSIS DELETE all files by extension


I'm trying to delete all files with a specific extension in a folder. I found this question on how to get all txt files and I thought about using that to get all files by extension and removing them, but I'm not sure how to do that.


Solution

  • There is no difference between listing and deleting files:

    FindFirst $0 $1 "$INSTDIR\*.txt"
    loop:
      StrCmp $1 "" done
      StrCpy $2 "$INSTDIR\$1"
      IfFileExists "$2\*.*" +2 ; A directory?
        Delete "$2"
      FindNext $0 $1
      Goto loop
    done:
    FindClose $0
    

    That being said, the documentation says wildcards are supported so you should be able to just do

    Delete "$INSTDIR\*.txt"