UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> ChangeFileExtension    
CODE

' Code courtesy of UtterAccess Wiki
' http://www.utteraccess.com/wiki/index.php/Category:FunctionLibrary
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' REV  DATE                          DESCRIPTION
' 1.0  2010-08-10              initial release
' 1.1  2010-09-12              revised function header
'
'==============================================================================
' NAME: ChangeFileExtension
' DESC: replaces extension with new one
' DEPENDANCIES:
'   GetFileExtension()
'   http://www.utteraccess.com/wiki/GetFileExtension
'   Version 2000+ (Access 97 will require InstrRev and Replace function replacements for compatibility)
'==============================================================================
Public Function ChangeFileExtension( _
   sFile As String, _
   sNewExt As String _
   ) As String
On Error GoTo Error_Proc
Dim Ret As String
'=========================
 Dim iPos As Integer
 Dim sOrigExt As String 'original file extension
'=========================

 sOrigExt = GetFileExtension(sFile)
 
 iPos = InStrRev(sFile, sOrigExt)
 
 If Left(sNewExt, 1) <> "." Then
   sNewExt = "." & sNewExt
 End If
 
 Ret = Left(sFile, iPos - 1) & Replace(sFile, sOrigExt, sNewExt, iPos, 1)
 
'=========================
Exit_Proc:
 ChangeFileExtension = Ret
 Exit Function
Error_Proc:
 MsgBox "Error: " & Trim(Str(Err.Number)) & vbCrLf & _
   "Desc: " & Err.Description & vbCrLf & vbCrLf & _
   "Module: modFileEval, Procedure: ChangeFileExtension" _
   , vbCritical, "Error!"
 Resume Exit_Proc
 Resume
End Function


Creative Commons License
ChangeFileExtension by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 4,000 times.  This page was last modified 08:26, 6 April 2011 by Jack Leach.   Disclaimers