Get number of subdirs in dir path: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{|align=right
{{PageAuthor|Afrow UK}}
|<small>Author: [[{{ns:2}}:Afrow UK|Afrow UK]] ([[{{ns:3}}:Afrow UK|talk]], [[{{ns:-1}}:Contributions/Afrow UK|contrib]])</small>
 
|}
<br style="clear:both;">
== 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 [http://nsis.sourceforge.net/archive/nsisweb.php?page=358&instances=0,11,211 UninstallDirs] function.
This is useful in conjunction with the [[Uninstall all dirs and subdirs created by your installer|UninstallDirs]] function.


== Usage ==
== Usage ==
Line 44: Line 42:


-Stu
-Stu
[[Category:Disk, Path & File Functions]]

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