Get last directory path part: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.)
m (Updated author links.)
Line 1: Line 1:
{|align=right
|<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 will get the last part of a directory path.
This script will get the last part of a directory path.
Line 47: Line 51:


-Stuart :)
-Stuart :)
Page author: [[User:Afrow UK|Afrow UK]]

Revision as of 02:58, 30 April 2005

Author: Afrow UK (talk, contrib)


Description

This script will get the last part of a directory path.

Usage

Push "C:\program files\geoffrey\files"
Call GetFileName
Pop $R0

$R0 is now "files"

You can also use this function to get the file extension of an entered file path. In the function replace...

StrCmp $2 "\" exit

...with

StrCmp $2 "." exit

The file extension (after the ".") will then be popped off the stack.

The Function

Function GetFileName
  Exch $0 ; input string
  Push $1
  Push $2
  StrCpy $1 0
  loop:
    IntOp $1 $1 - 1
    StrCpy $2 $0 1 $1
    StrCmp $2 "" exit2
    StrCmp $2 "\" exit1 ; replace "\" with "." if you want file extension
    Goto loop
  exit1:
    IntOp $1 $1 + 1
    StrCpy $0 $0 "" $1
  exit2:
    Pop $2
    Pop $1
    Exch $0
FunctionEnd

Written by KiCHiK

(I also wrote a similar script, but this one is better)

-Stuart :)