问题
everyone. I am trying to include some "parentdir" with files to my installer. The thing is: I use /r parameter to include all files and folders, like this:
File /r "parentdir\*.*"
This command include all files and subfolders.
Is any chance to include FILES ONLY from all subfolders(example below) to out directory?
What I have is:
<dir>parentdir
file1.txt
file2.txt
<dir> directory1
file3.txt
file4.txt
<dir> directory2
file5.txt
file6.txt
<dir> directory3
file6.txt
What I want to get in my OUT directory is:
<dir>parentdir
file1.txt
file2.txt
file3.txt
file4.txt
file5.txt
file6.txt
file6.txt
I've already tried to do like this:
SetOutPath "$INSTDIR\parentdir"
File "parentdir\directory1\*.*"
File "parentdir\directory2\*.*"
File "parentdir\directory2\directory3\*.*"
And I got what I want. BUT
Is any chance to do it not using names of subfolders? I need it in case when script won't know exact names of all subfolders (if new subfolders will be added).
May I make my installer that flexible?
Thank you!
回答1:
You can create a batch file (or any other program) that searches the disk and writes File
instructions to a .nsh file. Your .nsi would first use !system
to execute the external application that generates the .nsh and then !include
it:
Section
SetOutPath "$INSTDIR\parentdir"
!tempfile filelist
!system '"generatefilelist.bat" ".\parentdir" "${filelist}"'
!include "${filelist}"
!delfile "${filelist}"
SectionEnd
...and the batch-file might look something like this:
@echo off
FOR /R "%~1" %%A IN (*.txt) DO (
>> "%~2" echo.File "%%~A"
)
If the pattern is simple enough you don't need a separate batch-file, you can just use cmd.exe directly:
Section
SetOutPath "$INSTDIR\parentdir"
!tempfile filelist
!system 'FOR /R ".\parentdir" %A IN (*.txt) DO @( >> "${filelist}" echo.File "%~A" )'
!include "${filelist}"
!delfile "${filelist}"
SectionEnd
来源:https://stackoverflow.com/questions/36437253/nsis-how-to-recursively-include-all-files-only-from-source-folder-and-subfolde