Set Extension: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{PageAuthor|TrueparuEx}}
== Description ==
== Description ==
Simple function to set / change file extension.
Simple function to set / change file extension.
Line 6: Line 7:
   Push ".exe"
   Push ".exe"
   Push "C:\some dir\some file.txt"
   Push "C:\some dir\some file.txt"
   Call FixExtension
   Call SetExtension
   Pop $R0      ; $R0 = "C:\some dir\some file.exe"
   Pop $R0      ; $R0 = "C:\some dir\some file.exe"
</highlight-nsis>
</highlight-nsis>
Line 19: Line 20:
   Push $R3
   Push $R3


   StrCpy $R3 1
   StrCpy $R3 0


   trim_loop:
   trim_loop:
   StrCpy $R2 "$R0" 1 -$R3
   IntOp $R3 $R3 + 1
  StrCmp $R2 "\" trim_add 0
  StrCpy $R2 $R0 1 -$R3
  StrCmp $R2 "" trim_add 0
    StrCmp $R2 "\" trim_add
    StrCmp $R2 "/" trim_add
    StrCmp $R2 "" trim_add


  StrCmp $R2 "." 0 trim_cn
  StrCmp $R2 "." 0 trim_loop
  StrCpy $R2 "$R0" "" -$R3
    StrCpy $R2 $R0 "" -$R3
  StrCmp "$R2" "$R1" trim_ok 0
    StrCmp $R2 $R1 trim_ok
  StrCpy $R2 "$R0" -$R3
    StrCpy $R2 $R0 -$R3
  StrCpy $R0 "$R2$R1"
    StrCpy $R0 "$R2$R1"
  goto trim_ok
    goto trim_ok
 
  trim_cn:
  IntOp $R3 $R3 + 1
  goto trim_loop


   trim_add:
   trim_add:
   StrCpy $R0 "$R0$R1"
   StrCpy $R0 "$R0$R1"
   trim_ok:
   trim_ok:


Line 48: Line 46:
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>
[[Category:Disk, Path & File Functions]]

Latest revision as of 21:40, 22 May 2008

Author: TrueparuEx (talk, contrib)


Description

Simple function to set / change file extension.

Usage

  Push ".exe"
  Push "C:\some dir\some file.txt"
  Call SetExtension
  Pop $R0       ; $R0 = "C:\some dir\some file.exe"

Function

Function SetExtension
  Exch $R0
  Exch
  Exch $R1
  Push $R2
  Push $R3
 
  StrCpy $R3 0
 
  trim_loop:
  IntOp $R3 $R3 + 1
   StrCpy $R2 $R0 1 -$R3
    StrCmp $R2 "\" trim_add
    StrCmp $R2 "/" trim_add
    StrCmp $R2 "" trim_add
 
   StrCmp $R2 "." 0 trim_loop
    StrCpy $R2 $R0 "" -$R3
    StrCmp $R2 $R1 trim_ok
     StrCpy $R2 $R0 -$R3
     StrCpy $R0 "$R2$R1"
     goto trim_ok
 
  trim_add:
  StrCpy $R0 "$R0$R1"
  trim_ok:
 
  Pop $R3
  Pop $R2
  Pop $R1
  Exch $R0
FunctionEnd