2011-10-24 51 views
1

我目前有一张支票来查找$ INSTDIR中的所有文本文件,如下所示。NSIS查找所有.txt文件

但是,可能有子目录,如$ INSTDIR \ mySub,其中包含其他.txt文件。有没有办法保持类似的循环结构,但也搜索所有子目录?

FindFirst $R0 $R1 "$INSTDIR\*.txt" 
IfErrors ExitInstaller 0 
LoopIt: 
    Messagebox MB_OK "Do some processing on $R1" 
    FindNext $R0 $R1 
    IfErrors 0 LoopIt 

回答

2
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 
+0

静音模式有什么不同吗? http://stackoverflow.com/questions/8215733/nsis-find-files-in-silent-mode-not-working – jkh

1

尝试使用Locate函数 - 它可能是更好的解决方案。您可以编写选项以查找带有(或不带)子目录,定义掩码等。有关文档和示例,请参阅http://nsis.sourceforge.net/Locate