Get last directory path part: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library) |
m (Updated author and download links, and changed format of some pages.) |
||
Line 48: | Line 48: | ||
-Stuart :) | -Stuart :) | ||
Page author: Afrow UK | Page author: [[User:Afrow UK|Afrow UK]] |
Revision as of 12:35, 23 April 2005
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 :)
Page author: Afrow UK