Get last directory path part: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.) |
m (Added category links.) |
||
Line 51: | Line 51: | ||
-Stuart :) | -Stuart :) | ||
[[{{ns:14}}:Disk, Path & File Functions]] |
Revision as of 21:03, 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 :)