Get last directory path part: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Added category links.)
m (Adding new author and category links.)
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 will get the last part of a directory path.
This script will get the last part of a directory path.
Line 52: Line 50:
-Stuart :)
-Stuart :)


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

Revision as of 12:22, 24 June 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 :)