En segundo lugar perdón por haber puesto códigos que no funcionaban, andaba con prisa... :¬¬
Este es mi último código:
Código
Public Static Function MrFrogGetFileFast(ByRef sPath As String) As String Dim L As Long Dim lngPos As Long L = LenB(sPath) \ 2 lngPos = L - InStrRev(sPath, "\", L, vbBinaryCompare) MrFrogGetFileFast = RightB$(sPath, lngPos + lngPos) End Function
Test:
Código:
Option Explicit
Private cFC As New cFrogContest
Private Declare Sub PathStripPath Lib "shlwapi.dll" Alias "PathStripPathA" (ByVal pszPath As String)
Private Declare Function GetFileTitle Lib "comdlg32.dll" Alias "GetFileTitleA" (ByVal lpszFile As String, ByVal lpszTitle As String, ByVal cbBuf As Integer) As Integer
Public Static Function MrFrogGetFileFast(ByRef sPath As String) As String
Dim L As Long
Dim lngPos As Long
L = LenB(sPath) \ 2
lngPos = L - InStrRev(sPath, "\", L, vbBinaryCompare)
MrFrogGetFileFast = RightB$(sPath, lngPos + lngPos)
End Function
Public Function SacarFilenameE_Cv2(ByRef sPath As String) As String
SacarFilenameE_Cv2 = Right$(sPath, Len(sPath) - InStrRev(sPath, "\", Len(sPath), vbBinaryCompare))
End Function
Public Function SacarFilenameE_C(ByRef sPath As String) As String
SacarFilenameE_C = StrReverse$(Left$(StrReverse$(sPath), InStr(1, StrReverse(sPath), "\", vbBinaryCompare) - 1))
End Function
Public Function getFileNameIgnorante(ByVal path As String) As String
Dim cM As Integer
cM = InStrRev(path, "\") + 1
If cM = 0 Then Exit Function
getFileNameIgnorante = Mid(path, cM)
End Function
Public Function StripPathSeba(ByVal sPath As String) As String
Call PathStripPath(sPath)
StripPathSeba = sPath
End Function
Public Function getFileNameIgnoranteMODSeba(ByVal path As String) As String
getFileNameIgnoranteMODSeba = Mid$(path, InStrRev(path, "\") + 1)
End Function
Public Function nombre_archivoGrester(ByVal Ruta As String) As String
Dim partes() As String
partes = Split(Ruta, "\")
nombre_archivoGrester = partes(UBound(partes))
End Function
Public Function Fn7913(ByVal sPath As String) As String
Dim Buffer As String
Buffer = String(255, 0)
GetFileTitle sPath, Buffer, Len(Buffer)
Fn7913 = Left$(Buffer, InStr(1, Buffer, Chr$(0)) - 1)
End Function
Public Function GetFileName123(ByRef vPath As String) As String
GetFileName123 = Right$(vPath, Len(vPath) - InStrRev(vPath, "\"))
End Function
Private Sub Form_Load()
With cFC
.ContestName = "ObtenerNombreArchivo"
.Explanation = "Mas claro, hechale agua"
.SaveDirectory = App.path
.ReplaceFile = True
.Functions "Fn7913,MrFrogGetFileFast,GetFilename123,getFileNameIgnorante,getFileNameIgnoranteMODSeba,nombre_archivoGrester,SacarFilenameE_C,SacarFilenameE_Cv2,StripPathSeba"
.Arguments "C:\Documents and Settings\Llamazares\Mis documentos\Downloads\SexoDeRanas.avi"
.NumberOfLoops = 10000
.Result = "SexoDeRanas.avi"
.SetObject Me
.TestIt
.ShowTest
End With
End
End Sub
Private cFC As New cFrogContest
Private Declare Sub PathStripPath Lib "shlwapi.dll" Alias "PathStripPathA" (ByVal pszPath As String)
Private Declare Function GetFileTitle Lib "comdlg32.dll" Alias "GetFileTitleA" (ByVal lpszFile As String, ByVal lpszTitle As String, ByVal cbBuf As Integer) As Integer
Public Static Function MrFrogGetFileFast(ByRef sPath As String) As String
Dim L As Long
Dim lngPos As Long
L = LenB(sPath) \ 2
lngPos = L - InStrRev(sPath, "\", L, vbBinaryCompare)
MrFrogGetFileFast = RightB$(sPath, lngPos + lngPos)
End Function
Public Function SacarFilenameE_Cv2(ByRef sPath As String) As String
SacarFilenameE_Cv2 = Right$(sPath, Len(sPath) - InStrRev(sPath, "\", Len(sPath), vbBinaryCompare))
End Function
Public Function SacarFilenameE_C(ByRef sPath As String) As String
SacarFilenameE_C = StrReverse$(Left$(StrReverse$(sPath), InStr(1, StrReverse(sPath), "\", vbBinaryCompare) - 1))
End Function
Public Function getFileNameIgnorante(ByVal path As String) As String
Dim cM As Integer
cM = InStrRev(path, "\") + 1
If cM = 0 Then Exit Function
getFileNameIgnorante = Mid(path, cM)
End Function
Public Function StripPathSeba(ByVal sPath As String) As String
Call PathStripPath(sPath)
StripPathSeba = sPath
End Function
Public Function getFileNameIgnoranteMODSeba(ByVal path As String) As String
getFileNameIgnoranteMODSeba = Mid$(path, InStrRev(path, "\") + 1)
End Function
Public Function nombre_archivoGrester(ByVal Ruta As String) As String
Dim partes() As String
partes = Split(Ruta, "\")
nombre_archivoGrester = partes(UBound(partes))
End Function
Public Function Fn7913(ByVal sPath As String) As String
Dim Buffer As String
Buffer = String(255, 0)
GetFileTitle sPath, Buffer, Len(Buffer)
Fn7913 = Left$(Buffer, InStr(1, Buffer, Chr$(0)) - 1)
End Function
Public Function GetFileName123(ByRef vPath As String) As String
GetFileName123 = Right$(vPath, Len(vPath) - InStrRev(vPath, "\"))
End Function
Private Sub Form_Load()
With cFC
.ContestName = "ObtenerNombreArchivo"
.Explanation = "Mas claro, hechale agua"
.SaveDirectory = App.path
.ReplaceFile = True
.Functions "Fn7913,MrFrogGetFileFast,GetFilename123,getFileNameIgnorante,getFileNameIgnoranteMODSeba,nombre_archivoGrester,SacarFilenameE_C,SacarFilenameE_Cv2,StripPathSeba"
.Arguments "C:\Documents and Settings\Llamazares\Mis documentos\Downloads\SexoDeRanas.avi"
.NumberOfLoops = 10000
.Result = "SexoDeRanas.avi"
.SetObject Me
.TestIt
.ShowTest
End With
End
End Sub
Resultado :
Código:
================================================================================
º Contest Name : ObtenerNombreArchivo
º Explanation : Mas claro, hechale agua
º Arguments : C:\Documents and Settings\Llamazares\Mis documentos\Downloads\SexoDeRanas.avi
º Loops : 10000
º Date & Hour : 02-14-2011 <-> 02:54:08
================================================================================
Results [compiled] :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.- MrFrogGetFileFast -> 66,783268 msec
2.- SacarFilenameE_Cv2 -> 70,190216 msec
3.- MrFrogGetFileFast -> 74,492314 msec
4.- SacarFilenameE_C -> 78,365336 msec
5.- getFileNameIgnorante -> 79,100052 msec
6.- getFileNameIgnoranteMODSeba -> 88,191208 msec
7.- GetFilename123 -> 91,506807 msec
8.- nombre_archivoGrester -> 129,792677 msec
9.- Fn7913 -> 2159,992821 msec
================================================================================
º The following functions returns incorrect results :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.- StripPathSeba
================================================================================
>>> Test made by cFrogContest.cls <-> Visit foro.elhacker.net <<<
================================================================================
º Contest Name : ObtenerNombreArchivo
º Explanation : Mas claro, hechale agua
º Arguments : C:\Documents and Settings\Llamazares\Mis documentos\Downloads\SexoDeRanas.avi
º Loops : 10000
º Date & Hour : 02-14-2011 <-> 02:54:08
================================================================================
Results [compiled] :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.- MrFrogGetFileFast -> 66,783268 msec
2.- SacarFilenameE_Cv2 -> 70,190216 msec
3.- MrFrogGetFileFast -> 74,492314 msec
4.- SacarFilenameE_C -> 78,365336 msec
5.- getFileNameIgnorante -> 79,100052 msec
6.- getFileNameIgnoranteMODSeba -> 88,191208 msec
7.- GetFilename123 -> 91,506807 msec
8.- nombre_archivoGrester -> 129,792677 msec
9.- Fn7913 -> 2159,992821 msec
================================================================================
º The following functions returns incorrect results :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.- StripPathSeba
================================================================================
>>> Test made by cFrogContest.cls <-> Visit foro.elhacker.net <<<
================================================================================
Pd: Me alegra ver que usais mi clase
DoEvents!