How to copy files from the installer to the hard drive in NSIS, but only if they do not exist or are newer than existing ones?

I am currently using:

SetOutPath "$INSTDIR\folder\subfolder" File /r ..\Output\*.* 

The problem is that reloading all files will be overwritten.

Questions:

  • How to copy files from the installer only if they do not already exist in the target directory?

    and

  • How to overwrite those files in the target directory that are older than those installed in the installer?

Edit:

I found this macro: http://nsis.sourceforge.net/MoveFileFolder

+6
source share
2 answers

I think the best solution is to use the SetOverwrite flag:

http://nsis.sourceforge.net/Docs/Chapter4.html#4.8.2.8

This flag can be changed "on the fly" in the section.

So, to answer the question specifically:

 SetOverwrite off # Only copy if file does not exist File /r ..\Output\*.* SetOverwrite ifnewer # Only overwrite if installers' file is newer File /r ..\Output\*.* 
+6
source

Use a combination of IfFileExists and SetOverwrite :

 Section "Copy newer files" SetOverwrite ifnewer ; Set flag to owerwrite files only if they are newer than files in output dir IfFileExists $INSTDIR\program.exe FileExists FileDoesNotExist FileDoesNotExist: ; Copy file to output directory SetOutPath "$INSTDIR" File "program.exe" ; Flag from SetOverwrite is applied here FileExists: ; File exists - do nothing ; Continue ... SectionEnd 
+3
source

Source: https://habr.com/ru/post/921924/


All Articles