Get the Root Directory: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Added category links.)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{|align=right
{{PageAuthor|KiCHiK}}
|<small>Author: [[{{ns:2}}:KiCHiK|KiCHiK]] ([[{{ns:3}}:KiCHiK|talk]], [[{{ns:-1}}:Contributions/KiCHiK|contrib]])</small>
 
|}
<br style="clear:both;">
== Description ==
== Description ==
This function will return the root directory of a given path. It only accepts full paths. If you need to convert a relative path to a full path you can use GetFullPathName.
This function will return the root directory of a given path. It only accepts full paths. If you need to convert a relative path to a full path you can use GetFullPathName.
== Notes ==
Do you want to [[CheckSpaceFree]] at $INSTDIR? Please see the notes there.


== Examples ==
== Examples ==
Line 54: Line 55:
FunctionEnd</highlight-nsis>
FunctionEnd</highlight-nsis>


[[{{ns:14}}:Disk, Path & File Functions]]
[[Category:Disk, Path & File Functions]]

Latest revision as of 15:24, 13 January 2007

Author: KiCHiK (talk, contrib)


Description

This function will return the root directory of a given path. It only accepts full paths. If you need to convert a relative path to a full path you can use GetFullPathName.

Notes

Do you want to CheckSpaceFree at $INSTDIR? Please see the notes there.

Examples

Push "C:\Program Files\NSIS\"
Call GetRoot
Pop $0
DetailPrint "$0 should be C:"
 
Push "\\SuperPimp\NSIS\Source\exehead\Ui.c"
Call GetRoot
Pop $0
DetailPrint "$0 should be \\SuperPimp\NSIS"

The function:

Function GetRoot
  Exch $0
  Push $1
  Push $2
  Push $3
  Push $4
 
  StrCpy $1 $0 2
  StrCmp $1 "\\" UNC
    StrCpy $0 $1
    Goto done
 
UNC:
  StrCpy $2 3
  StrLen $3 $0
  loop:
    IntCmp $2 $3 "" "" loopend
    StrCpy $1 $0 1 $2
    IntOp $2 $2 + 1
    StrCmp $1 "\" loopend loop
  loopend:
    StrCmp $4 "1" +3
      StrCpy $4 1
      Goto loop
    IntOp $2 $2 - 1
    StrCpy $0 $0 $2
 
done:
  Pop $4
  Pop $3
  Pop $2
  Pop $1
  Exch $0
FunctionEnd