NSIS - 如何递归包含仅来自源文件夹和子文件夹的所有文件? [英] NSIS - how to recursively include all files only from source folder and subfolders?

查看:86
本文介绍了NSIS - 如何递归包含仅来自源文件夹和子文件夹的所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家.我试图在我的安装程序中包含一些带有文件的parentdir".问题是:我使用/r 参数来包含所有文件和文件夹,如下所示:

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.

是否有机会仅将所有子文件夹(下面的示例)中的文件包含到 out 目录中?

Is any chance to include FILES ONLY from all subfolders(example below) to out directory?

我拥有的是:

<dir>parentdir
  file1.txt
  file2.txt
  <dir> directory1
       file3.txt
       file4.txt
  <dir> directory2
       file5.txt
       file6.txt
       <dir> directory3
             file6.txt

我想在我的 OUT 目录中得到的是:

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

我已经尝试这样做了:

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?

谢谢!

推荐答案

您可以创建一个批处理文件(或任何其他程序)来搜索磁盘并将 File 指令写入 .nsh 文件.您的 .nsi 将首先使用 !system 来执行生成 .nsh 的外部应用程序,然后 !include 它:

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"
)

如果模式足够简单,您不需要单独的批处理文件,您可以直接使用 cmd.exe:

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

这篇关于NSIS - 如何递归包含仅来自源文件夹和子文件夹的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆