Archive: Replace files recursively


Replace files recursively
Hello, guys. I got a problem here, I can not find a simple solution for. My installer extracts a zip-archive to a temporary folder TEMP. Then it should copy files and directories from that temporary to the installation directory INSTALL. Some files should be copied and some of them not, depending on some conditions. I use CopyFiles for that. Now the problem is that I can not say to CopyFiles: "Look in each folder TEMP\X and copy the files from TEMP\X to folder INSTALL\X" if I do not know exactly which folders are contained in TEMP after the archive was extracted. Is there a way to handle this problem except for doing a search for all folders in TEMP explicitly?

BR
Ewgenij


The only thought that comes to mind is perhaps using Windows XCOPY (via the nsExec plugin). This might give you more options without spending a lot of time developing something within NSIS. This assumes that the "conditions" you refer to could be handled easily.

From what I can tell, Xcopy is included with all versions of Windows. (For a complete list of XCOPY options, just go to a command prompt and type "xcopy /?")


Hey, that helped! Thank you a lot! But I got another question:)

I have the following command:
xcopy "$Source\*" "$OUTDIR" /Y /E /EXCLUDE:$EXEDIR\exclude.txt

In the file exclude.txt I have the names of files, which should not be copied. Now, what if $EXEDIR contains blanks? The command line does not accept that. Quotes do no help. The only solution I see is to make $EXEDIR the working directory temporarily and then to call xcopy. But is there maybe another solution?

BR
Ewgenij


Changing the working directory is probably the best option.

Another might be to use use the folder's short name. Every file/folder in Windows should have a short-named equivalent. Usually, it's the first 6 characters of the file name, followed by a tilde (~) and then a number.

To see them, go to a command prompt and type dir /x. (I think there's also an API call to get them; I'm just not sure head what it is off the top of my head...)


This should get you closer. I keep getting an error that my exclude file can not be read, however it does take the parameter correctly. Not sure how to format the exclude.txt file so that may be my problem.


nsExec::ExecToStack '"$SYSDIR\cmd.exe" /c xcopy.exe "$Source\*" "$OUTDIR" /Y /E /I /EXCLUDE:"$EXEDIR\Exclude.txt"'

Originally posted by pbingel
I keep getting an error that my exclude file can not be read, however it does take the parameter correctly. Not sure how to format the exclude.txt file so that may be my problem
I had the same error message, but the real reason is that xcopy (more precisely, the shell) does not accept the quotas around $EXEDIR\Exclude.txt. That is the true reason, not the format of the file! It takes the parameter correctly, but for some reason can not process it properly.

Ok, well I made a slight modification and now it works. I had to put the exclude.txt in the same directory as the .exe. DOS looks in the current directory first so no need to give a full path and therefore changed the code to:


nsExec::ExecToStack '"$SYSDIR\cmd.exe" /c xcopy.exe "$Source\*" "$OUTDIR" /Y /E /I /EXCLUDE:Exclude.txt'
Pop $0
Pop $1
MessageBox MB_OK $0 ;Should be 0
MessageBox MB_OK $1 ;Should be the files copied


This worked for me and xcopy did exclude the files that I had listed in the Exclude.txt as expected. :D

Since you no longer have any odd quotation marks you can go back to the older style without including '"$SYSDIR\cmd.exe" /c'


nsExec::ExecToStack 'xcopy.exe "$EXEDIR\JTCW\*.*" "$EXEDIR\JTCW2\" /I /Y /E /EXCLUDE:Exclude.txt'