Get extension of file: 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|opher}}
|<small>Author: [[{{ns:2}}:opher|opher]] ([[{{ns:3}}:opher|talk]], [[{{ns:-1}}:Contributions/opher|contrib]])</small>
 
|}
<br style="clear:both;">
== Description ==
== Description ==
This is based on the work of Afrow UK.
This is based on the work of Afrow UK.
Line 46: Line 44:
</highlight-nsis>
</highlight-nsis>


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

Revision as of 12:22, 24 June 2005

Author: opher (talk, contrib)


Description

This is based on the work of Afrow UK. This more accuretly reports the extention: For path "C:\some dir\some file with no extention"

 Afrow UK's implementation will return the original string as "extention"

For path "C:\Installation.CD\some file with no extention"

 Afrow UK's implementation will return "CD\some file with no extention" as extention.

In both cases this function will return "" (empty) as extention.

Usage

  Push "C:\some path\filename.extention"
  Call GetFileExt
  Pop $R0             ; $R0 = "extention"

The Function

Function GetFileExt
  Exch $0 ; input string
  Push $1
  Push $2
  StrCpy $1 0
  loop:
    IntOp $1 $1 - 1
    StrCpy $2 $0 1 $1
    StrCmp $2 "" empty
    StrCmp $2 "\" empty
    StrCmp $2 "." found
    Goto loop
  empty:
    StrCpy $0 ""
    goto exit
  found:
    IntOp $1 $1 + 1
    StrCpy $0 $0 "" $1
  exit:
    Pop $2
    Pop $1
    Exch $0
FunctionEnd