简体   繁体   English

NSIS查找所有.txt文件

[英]NSIS Find all .txt files

I currently have a check to find all text files in $INSTDIR, shown below. 我目前正在检查以找到$ INSTDIR中的所有文本文件,如下所示。

However, there could potentially be subdirectories, such as $INSTDIR\\mySub, which contains additional .txt files. 但是,可能存在子目录,例如$ INSTDIR \\ mySub,其中包含其他.txt文件。 Is there a way to keep a similar loop structure but search all subdirectories as well? 有没有办法保持类似的循环结构,但还要搜索所有子目录?

FindFirst $R0 $R1 "$INSTDIR\*.txt"
IfErrors ExitInstaller 0
LoopIt:
  Messagebox MB_OK "Do some processing on $R1"
  FindNext $R0 $R1
  IfErrors 0 LoopIt
Function ProcessTextFiles
Exch $0
Push $1
Push $2
FindFirst $1 $2 "$0\*.txt"
loop:
    IfErrors end
    DetailPrint 'Found "$0\$2"'
    FindNext $1 $2
    goto loop
end:
FindClose $1
FindFirst $1 $2 "$0\*.*"
dirloop:
    IfErrors dirend 
    IfFileExists "$0\$2\*.*" 0 dirnext
    StrCmp $2 "." dirnext
    StrCmp $2 ".." dirnext
    Push "$0\$2"
    call ${__FUNCTION__}
dirnext:
    FindNext $1 $2
    goto dirloop
dirend:
FindClose $1
Pop $2
Pop $1
Pop $0
FunctionEnd

section
push "$InstDir"
call ProcessTextFiles
sectionend

Try to use the Locate function instead -- it could be much better solution. 尝试使用Locate函数 - 它可能是更好的解决方案。 You can write options to find with (or without) subdirectories, define mask and so on. 您可以编写选项以查找具有(或不具有)子目录,定义掩码等。 See http://nsis.sourceforge.net/Locate for doc and examples. 有关doc和示例,请参见http://nsis.sourceforge.net/Locate

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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