简体   繁体   中英

NSIS - How to install multiple files with similar folder structures using a single command?

Problem

I have multiple files in very similarly structured folders that I want to install in one common folder.

I can do this by manually specifying each file I want to add, like so:

SetOutPath "$INSTDIR\Final\Destination"
File /r ".\ParentFolder\Folder1\Same\Path\For\All\Thing1.ext"
File /r ".\ParentFolder\Folder2\Same\Path\For\All\Thing2.ext"
File /r ".\ParentFolder\Folder3\Same\Path\For\All\Thing3.ext"
File /r ".\ParentFolder\Folder4\Same\Path\For\All\Thing4.ext"
File /r ".\ParentFolder\Folder5\Same\Path\For\All\Thing5.ext"

However, there are 50+ of these files, and they are likely to change, so I'd prefer to do this in a way that won't require editing the NSIS in the future.

What I have Tried

I tried putting in wildcards, like so:

SetOutPath "$INSTDIR\Final\Destination"
File /r ".\ParentFolder\*\Same\Path\For\All\*.ext"

However, I get the message File: ".\ParentFolder\*\Same\Path\For\All\*.ext" -> no files found.

Question

Is there something wrong with using multiple wildcards * in my File query?

What would be the correct way to query multiple files in different folders?

You can't put wildcards anywhere, only in the filename unfortunately.

What you can do however is to use !system to execute a batch file (or any other command or application) that writes NSIS instructions to a file you can !include :

Section

SetOutPath $InstDir
!tempfile folders ; temporary .nsh
!system 'for /D %A in (.\ParentFolder\*) do @>>"${folders}" echo File /r "%~A\Same\Path\For\All\*.ext"'
!include "${folders}"
!delfile "${folders}"

SectionEnd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM