Wednesday, August 19, 2009

Change a file extension

Maybe you want to change the file extension to your needs using VB6. Following simple way to change the file extension:

Public Function ChangeFileExt(ByVal aFilename As String, ByVal NewExt As
String) As Boolean
Dim p As Long
Dim bp As Long
Dim nFileName As String

On Error Resume Next
ChangeFileExt = False
If aFilename = "" Then Exit Function
p = 0
Do
bp = p
p = InStr(p + 1, aFilename, ".", vbBinaryCompare)

Loop Until p = 0

If bp > 0 Then
nFileName = Left(aFilename, bp - 1)
Else
nFileName = aFilename
End If

nFileName = nFileName & "." & NewExt

Err.Clear

Name aFilename As nFileName

If Err.Number = 0 Then ChangeFileExt = True

End Function


1 comment:

  1. check this website also , its helpful

    http://channels.dal.net/coder

    ReplyDelete