elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  [RETO] Obtener nombre de archivo
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 2 [3] 4 Ir Abajo Respuesta Imprimir
Autor Tema: [RETO] Obtener nombre de archivo  (Leído 15,740 veces)
Psyke1
Wiki

Desconectado Desconectado

Mensajes: 1.089



Ver Perfil WWW
Re: [RETO] Obtener nombre de archivo
« Respuesta #20 en: 14 Febrero 2011, 02:45 am »

En primer lugar gracias a todos por participar! :D
En segundo lugar perdón por haber puesto códigos que no funcionaban, andaba con prisa... :¬¬
Este es mi último código:

Código
  1. Public Static Function MrFrogGetFileFast(ByRef sPath As String) As String
  2. Dim L                                               As Long
  3. Dim lngPos                                          As Long
  4.  
  5.    L = LenB(sPath) \ 2
  6.    lngPos = L - InStrRev(sPath, "\", L, vbBinaryCompare)
  7.    MrFrogGetFileFast = RightB$(sPath, lngPos + lngPos)
  8. 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

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 <<<
================================================================================

Pd: Me alegra ver que usais mi clase :-*

DoEvents! :P


« Última modificación: 14 Febrero 2011, 02:58 am por Mr. Frog © » En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: [RETO] Obtener nombre de archivo
« Respuesta #21 en: 14 Febrero 2011, 09:33 am »


Pd: Me alegra ver que usais mi clase :-*


mmm, no habia casi ninguna publicacion en el hilo q no lo mensionaras...


Quien sea más rápido, gana. ;)
Se testeará con cFrogContest.cls :P




@Seba123neo
Jajajaj hice la clase precisamente para ahorrarte el trabajo! :xD


P.D.: mi funcion no figuro en la prueba... jaja las limitaciones de una clase que hacen discriminar a otras, pero bueno ni que.

Dulces Lunas!¡.


En línea

The Dark Shadow is my passion.
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: [RETO] Obtener nombre de archivo
« Respuesta #22 en: 14 Febrero 2011, 10:38 am »

.
Le hice una pequeña modificación a mi función GetPathInfo para que los parametros sean usados con el operador Or.

No será la más rápida pero si la más dinamica  :rolleyes:.

Código
  1.  
  2. '
  3. ' ////////////////////////////////////////////////////////////////
  4. ' // Autor: BlackZeroX ( Ortega Avila Miguel Angel )            //
  5. ' //                                                            //
  6. ' // Web: http://InfrAngeluX.Sytes.Net/                         //
  7. ' //                                                            //
  8. ' // |-> Pueden Distribuir Este Código siempre y cuando         //
  9. ' // no se eliminen los créditos originales de este código      //
  10. ' // No importando que sea modificado/editado o engrandecido    //
  11. ' // o achicado, si es en base a este código                    //
  12. ' ////////////////////////////////////////////////////////////////
  13. ' // http://infrangelux.hostei.com/index.php?option=com_content&view=article&id=17:artgetpatchinfo&catid=2:catprocmanager&Itemid=8
  14. ' ////////////////////////////////////////////////////////////////
  15.  
  16. Option Explicit
  17. Enum GetFileStr
  18.    Extensión = 1
  19.    FileName = 2
  20.    Ruta = 4
  21. End Enum
  22. Public Function GetPatchInfo(ByVal StrRutaFull As String, Optional ByVal Options As GetFileStr = FileName) As String
  23. Dim lng_ptr(1)              As Long
  24. Dim lng_aux                 As Long
  25.    lng_aux = Len(StrRutaFull)
  26.    lng_ptr(0) = InStrRev(StrRutaFull, "\")
  27.    If lng_ptr(0) > 0 Then
  28.        lng_ptr(1) = InStrRev(StrRutaFull, ".")
  29.        If lng_ptr(1) > 0 And Not lng_ptr(0) < lng_ptr(1) Then
  30.            lng_ptr(1) = lng_aux + 1
  31.        End If
  32.        If (Options And Ruta) = Ruta Then
  33.            GetPatchInfo = Mid$(StrRutaFull, 1, lng_ptr(0)) & GetPatchInfo
  34.        End If
  35.        If (Options And FileName) = FileName Then
  36.            If lng_ptr(1) = lng_aux Then
  37.                lng_aux = lng_aux - lng_ptr(0) - 1
  38.            Else
  39.                lng_aux = lng_ptr(1) - lng_ptr(0) - 1
  40.            End If
  41.            GetPatchInfo = GetPatchInfo & Mid$(StrRutaFull, lng_ptr(0) + 1, lng_aux)
  42.        End If
  43.        If (Options And Extensión) = Extensión Then
  44.            GetPatchInfo = GetPatchInfo & Mid$(StrRutaFull, lng_ptr(1), lng_ptr(1))
  45.        End If
  46.    End If
  47. End Function
  48.  
  49.  

Temibles Lunas!¡.
« Última modificación: 15 Febrero 2011, 04:11 am por BlackZeroX▓▓▒▒░░ » En línea

The Dark Shadow is my passion.
Psyke1
Wiki

Desconectado Desconectado

Mensajes: 1.089



Ver Perfil WWW
Re: [RETO] Obtener nombre de archivo
« Respuesta #23 en: 14 Febrero 2011, 13:34 pm »

@Black
Siento no haber puesto tu función, no me fije al no poner el codigo directo en el hilo... :rolleyes:
El inconveniente de mi clase es que todas las funciones deben tener los mismos argumentos. :-(
Únicamente añadí la mia al test de Elemental Code. :silbar:
Igual se me ocurre una version aún más rápida de hacerlo :D

DoEvents! :P
En línea

Elemental Code


Desconectado Desconectado

Mensajes: 622


Im beyond the system


Ver Perfil
Re: [RETO] Obtener nombre de archivo
« Respuesta #24 en: 14 Febrero 2011, 17:50 pm »

a pesar de que el hombre rana algo raro hizo porque dio mas rapido mi segunda funcion que la primera

el pibe gano.
Código:
================================================================================
º Contest Name : ObtenerNombreArchivo
º Explanation  : Mas claro, hechale agua
º Arguments    : C:\Documents and Settings\Llamazares\Mis documentos\Downloads\SexoDeRanas.avi
º Loops        : 1000
º Date & Hour  : 02-14-2011 <-> 13:47:25
================================================================================
Results [compiled] :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.- MrFrogGetFileFast                                   -> 23,140550 msec
2.- SacarFilenameE_C                                    -> 25,971375 msec
3.- SacarFilenameE_Cv2                                  -> 29,063666 msec
4.- getFileNameIgnorante                                -> 31,133647 msec
5.- SacarFilenameE_CB                                   -> 33,288770 msec
6.- getFileNameIgnoranteMODSeba                         -> 37,030797 msec
7.- GetFilename123                                      -> 37,921469 msec
8.- nombre_archivoGrester                               -> 48,419315 msec
9.- Fn7913                                              -> 257,055627 msec
================================================================================
º The following functions returns incorrect results :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.- StripPathSeba
================================================================================
>>> Test made by cFrogContest.cls <-> Visit foro.elhacker.net <<<
================================================================================

Se me hace medio imposible que la segunda funcion que hice funcione mas rapido que la primera ya que instrReverse es casi el doble de lento que el instr comun :S
En línea

I CODE FOR $$$
Programo por $$$
Hago tareas, trabajos para la facultad, lo que sea en VB6.0

Mis programas
Psyke1
Wiki

Desconectado Desconectado

Mensajes: 1.089



Ver Perfil WWW
Re: [RETO] Obtener nombre de archivo
« Respuesta #25 en: 14 Febrero 2011, 19:36 pm »

@Elemental Code:
No hice nada raro, compilé, ejecute y eso salió. El resultado puede tener pequeñas variaciones. Lo puedes ver tambien en el test de Black.
Repetí el test y me sale mas rápida tu segunda.

Debes tener en cuenta que a mayor número de funciones utilizadas, generalmente emplearás más tiempo.

2ª función :
Código
  1. Right$(sPath, Len(sPath) - InStrRev(sPath, "\", Len(sPath), vbBinaryCompare))
Funciones utilizadas:
1 Right()
2 Len()
1 InstrRev()

Total : 4

1ª función :
Código
  1. StrReverse$(Left$(StrReverse$(sPath), InStr(1, StrReverse(sPath), "\", vbBinaryCompare) - 1))
Funciones utilizadas:
3 StrReverse()
1 Left()
1 Instr()

Total : 5

DoEvents! :P
En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [RETO] Obtener nombre de archivo
« Respuesta #26 en: 14 Febrero 2011, 21:03 pm »

En una clase, GetFile05:
Código:
' By Chris Lucas, cdl1051@earthlink.net, 20011204
' Thanks to Olaf for the class implementation concept

Option Explicit

Private Declare Function ArrPtr& Lib "msvbvm60.dll" Alias "VarPtr" (ptr() As Any)
Private Declare Sub RtlMoveMemory Lib "kernel32" (dst As Any, src As Any, ByVal nBytes&)

Private SafeArrayHeader(5) As Long
Private SafeArray() As Long

Private Sub Class_Initialize()
    SafeArrayHeader(0) = 1                ' Number of dimensions
    SafeArrayHeader(1) = 4                ' Bytes per element (long = 4)
    SafeArrayHeader(4) = &H7FFFFFFF       ' Array size

    ' Force SafeArray to use SafeArrayHeader as its own header
    RtlMoveMemory ByVal ArrPtr(SafeArray), VarPtr(SafeArrayHeader(0)), 4
End Sub

Friend Function GetExtension06(sText As String) As String
    Dim i&, SLen&, tmp1&, tmp2&

    SafeArrayHeader(3) = StrPtr(sText)
    SLen = LenB(sText) \ 2

    If (SLen And 1) Then
        If (SafeArray(SLen \ 2) And &HFFFF&) = &H2E& Then Exit Function
    End If

    For i = SLen \ 2 - 1 To 0 Step -1
        tmp1 = SafeArray(i)
        tmp2 = (tmp1 And &HFFFF0000)
        If tmp2 = &H2E0000 Then GoTo HiWord
        If tmp2 = &H5C0000 Then Exit Function
        tmp2 = (tmp1 And &HFFFF&)
        If tmp2 = &H2E& Then GoTo LoWord
        If tmp2 = &H5C& Then Exit Function
    Next i

    Exit Function

HiWord:
    GetExtension06 = RightB$(sText, SLen + SLen - i - i - i - i - 4)
    Exit Function
LoWord:
    GetExtension06 = RightB$(sText, SLen + SLen - i - i - i - i - 2)

End Function

Friend Function GetFile05(sText As String) As String
    Dim i&, SLen&, tmp1&

    SafeArrayHeader(3) = StrPtr(sText):
    SLen = LenB(sText) \ 2

    If (SLen And 1&) Then
        If (SafeArray(SLen \ 2) And &HFFFF&) = &H5C& Then Exit Function
    End If

    For i = SLen \ 2 - 1 To 0 Step -1
        tmp1 = SafeArray(i)
        If (tmp1 And &HFFFF0000) = &H5C0000 Then GoTo HiWord
        If (tmp1 And &HFFFF&) = &H5C& Then GoTo LoWord
    Next i

HiWord:
    GetFile05 = RightB$(sText, SLen + SLen - i - i - i - i - 4)
    Exit Function
LoWord:
    GetFile05 = RightB$(sText, SLen + SLen - i - i - i - i - 2)

End Function

Friend Function GetPath05(sText As String) As String
    Dim i&, SLen&, tmp1&

    SafeArrayHeader(3) = StrPtr(sText):
    SLen = LenB(sText) \ 2

    If (SLen And 1) Then
        If (SafeArray(SLen \ 2) And &HFFFF&) = &H5C& Then
            GetPath05 = sText
            Exit Function
        End If
    End If

    For i = SLen \ 2 - 1 To 0 Step -1
        tmp1 = SafeArray(i)
        If (tmp1 And &HFFFF0000) = &H5C0000 Then GoTo HiWord
        If (tmp1 And &HFFFF&) = &H5C& Then GoTo LoWord
    Next i

    GetPath05 = sText
    Exit Function
HiWord:
    GetPath05 = LeftB$(sText, i + i + i + i + 4)
    Exit Function
LoWord:
    GetPath05 = LeftB$(sText, i + i + i + i + 2)

End Function

Private Sub Class_Terminate()
    ' Make SafeArray once again use its own header
    ' If this code doesn't run the IDE will crash
    RtlMoveMemory ByVal ArrPtr(SafeArray), 0&, 4
End Sub
Código:
http://xbeat.net/vbspeed/c_GetFile.htm
Ante cualquier duda, NO es mio! :P
En línea

Psyke1
Wiki

Desconectado Desconectado

Mensajes: 1.089



Ver Perfil WWW
Re: [RETO] Obtener nombre de archivo
« Respuesta #27 en: 14 Febrero 2011, 21:25 pm »

Lo pongo así:
Código
  1. Private c As New Class1
  2.  
  3. Public Function GetFilevbspeed(ByRef s As String) As String
  4.    GetFilevbspeed = c.GetFile05(s)
  5. End Function

Y estos son los resultados:
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 <-> 21:23:28
================================================================================
Results [compiled] :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.- MrFrogGetFileFast                                   -> 67,317405 msec
2.- SacarFilenameE_Cv2                                  -> 69,679881 msec
3.- SacarFilenameE_C                                    -> 76,798269 msec
4.- getFileNameIgnorante                                -> 78,093355 msec
5.- getFileNameIgnoranteMODSeba                         -> 85,564123 msec
6.- GetFilename123                                      -> 95,046462 msec
7.- GetFilevbspeed                                      -> 102,299685 msec
8.- Reto_GetPatchInfo                                   -> 117,060663 msec
9.- nombre_archivoGrester                               -> 129,081305 msec
10.- Fn7913                               -> 1818,863233 msec
================================================================================
º The following functions returns incorrect results :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.- StripPathSeba
================================================================================
>>> Test made by cFrogContest.cls <-> Visit foro.elhacker.net <<<
================================================================================
¿No debería ser más rápida? :huh:

DoEvents! :P
En línea

Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [RETO] Obtener nombre de archivo
« Respuesta #28 en: 14 Febrero 2011, 21:32 pm »

Tal vez deberias hacerlo asi:
Código:
Private c As Class1
 
sub Main()
set c = new Class1
end sub

Public Function GetFilevbspeed(ByRef s As String) As String
    GetFilevbspeed = c.GetFile05(s)
End Function

De la otra forma creo que se llama al Class_Initialize cada vez :huh:
En línea

Psyke1
Wiki

Desconectado Desconectado

Mensajes: 1.089



Ver Perfil WWW
Re: [RETO] Obtener nombre de archivo
« Respuesta #29 en: 14 Febrero 2011, 21:35 pm »

@Karcrack
Mismos resutlados...  :silbar:

DoEvents! :P
En línea

Páginas: 1 2 [3] 4 Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Batch] obtener nombre de archivo (solucionado)
Scripting
corax 2 10,639 Último mensaje 23 Junio 2009, 20:29 pm
por corax
Obtener el nombre de PC
Programación C/C++
.:WindHack:. 1 2,235 Último mensaje 16 Mayo 2010, 21:40 pm
por Foxy Rider
Obtener ruta y nombre de archivo por el PID
Programación C/C++
Distorsion 5 5,562 Último mensaje 13 Enero 2011, 15:11 pm
por Distorsion
[Sockets] Obtener Nombre del archivo
.NET (C#, VB.NET, ASP)
kub0x 3 2,777 Último mensaje 14 Abril 2012, 20:06 pm
por kub0x
[RETO] Obtener archivo Web.Config
Programación General
n3oze3kr 1 1,774 Último mensaje 17 Febrero 2015, 22:35 pm
por engel lex
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines