Get number of subdirs in dir path: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(→‎Description: fixed wiki ref)
 
Line 3: Line 3:
== Description ==
== Description ==
This script gets the number of sub dirs in a directory path (string)
This script gets the number of sub dirs in a directory path (string)
This is useful in conjunction with the [[Uninstall all dirs and subdirs created by your installer]] function.
This is useful in conjunction with the [[Uninstall all dirs and subdirs created by your installer|UninstallDirs]] function.


== Usage ==
== Usage ==

Latest revision as of 04:17, 17 April 2010

Author: Afrow UK (talk, contrib)


Description

This script gets the number of sub dirs in a directory path (string) This is useful in conjunction with the UninstallDirs function.

Usage

Push $INSTDIR #input
 Call SubdirsAmount
Pop $R0 ;number of subdirs in $INSTDIR

The Function

Function SubdirsAmount
Exch $R0 ;input string
Push $R1
Push $R2
Push $R3
Push $R4
 StrCpy $R1 0
 StrLen $R2 $R0
loop:
 IntOp $R1 $R1 + 1
  StrCpy $R3 $R0 1 -$R1
 StrCmp $R1 $R2 exit
 StrCmp $R3 "\" 0 loop
  IntOp $R4 $R4 + 1
Goto loop
exit:
StrCpy $R0 $R4
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Exch $R0 ;output
FunctionEnd

Created for tderouin after this topic on the NSIS Forums.

-Stu