Get base file name: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library)
 
m (Adding new author and category links.)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{PageAuthor|comperio}}
== Description ==
== Description ==
The following function takes a file name from the top of the stack and return the base name (file name minus extension).  This is like the "GetBaseName" function of VBScript.
The following function takes a file name from the top of the stack and return the base name (file name minus extension).  This is like the "GetBaseName" function of VBScript.
Line 18: Line 20:
     Push $4  ; New string
     Push $4  ; New string
     strCpy $4 ""
     strCpy $4 ""
     StrCpy $1 "x$1"
    ; I add 'x' to the string to make it easier to
    ;  use with my pointer variable
     StrCpy $1 "x$1"
     strCpy $2 "0"
     strCpy $2 "0"
   StartBaseLoop:
   StartBaseLoop:
Line 36: Line 40:
</highlight-nsis>
</highlight-nsis>


Page author: comperio
[[Category:String Functions]]

Latest revision as of 12:21, 24 June 2005

Author: comperio (talk, contrib)


Description

The following function takes a file name from the top of the stack and return the base name (file name minus extension). This is like the "GetBaseName" function of VBScript.

The Function

Function GetBaseName
    ; This function takes a file name and returns the base name (no extension)
    ; Input is from the top of the stack
    ; Usage example:
    ; push (file name)
    ; call GetBaseName
    ; pop (file name)
 
 
    Exch $1  ; Initial value
    Push $2  ; Pointer variable
    Push $3  ; single character (temp)
    Push $4  ; New string
    strCpy $4 ""
    ; I add 'x' to the string to make it easier to 
    ;  use with my pointer variable
    StrCpy $1 "x$1"  
    strCpy $2 "0"
  StartBaseLoop:
    IntOp $2 $2 + 1
    StrCpy $3 $1 1 $2
    strCmp $3 "." ExitBaseLoop
    StrCmp $3 "" ExitBaseLoop
    StrCpy $4 "$4$3"
    Goto StartBaseLoop
  ExitBaseLoop:
    StrCpy $1 $4
    Pop $4
    Pop $3
    Pop $2
    Exch $1
FunctionEnd