10/10/2008

Visual Basic ile Dosya Uzantılarını bulmak

Aşağıdaki fonksiyon bir dosyanın uzantısını döndürüyor.

Function GetExtension(Filename As String)

Dim PthPos, ExtPos As Integer

For i = Len(Filename) To 1 Step -1 ' Go from the Length of the filename, to the first character by 1.

If Mid(Filename, i, 1) = "." Then ' If the current position is '.' then...

ExtPos = i ' ...Change the ExtPos to the number.

For j = Len(Filename) To 1 Step -1 ' Do the Same...

If Mid(Filename, j, 1) = "" Then ' ...but for ''.

PthPos = j ' Change the PthPos to the number.

Exit For ' Since we found it, don't search any more.

End If

Next j

Exit For ' Since we found it, don't search any more.

End If

Next i

If PthPos > ExtPos Then

Exit Function ' No extension.

Else

If ExtPos = 0 Then Exit Function ' If there is not extension, then exit sub.

GetExtension = Mid(Filename, ExtPos + 1, Len(Filename) - ExtPos) 'Messagebox the Extension

End If

End Function

Fonksiyonu aşağıdaki gibi çağırabilirsiniz.

FileExt = GetExtension("c:windowsvbvb.exe")

EkleBunu Sosyal Paylaşım Butonu


Yorum yaz! :: Arkadaşına Gönder!

0 yorum yazılmıştır

<- Son Sayfa :: Sonraki Sayfa ->