Buscar archivos
Hola, necesito que busque un archivo, pero que me de el directorio en donde se encuentra ese archivo, por ejemplo yo tengo el archivo c:pepe123sol.exe
Entonces cuando busca sol.exe por toda la pc, al encontrarlo que me diga c:pepe123 (sin sol.exe)
Muchas Gracias, aqui abajo dejo un codigo que encontre, que es para bsucar archivos, trate de modificarlo, pero se me cuelga vb.
Private Sub Image5_Click()
Text2.Text = PathTo("hl.exe")
End Sub
Function PathTo(strFile As String) As String
Dim x As Integer
Dim strDirs As String
Dim strDir As String
Dim strEntry As String
strDirs = "c:" & vbNullChar
Do While Len(strDirs)
x = InStr(strDirs, vbNullChar)
strDir = Left$(strDirs, x - 1)
strDirs = Mid$(strDirs, x + 1)
If Len(Dir$(strDir & strFile)) Then
PathTo = strDir & Dir$(strDir & strFile)
Exit Function
End If
strEntry = Dir$(strDir & "*.*", vbDirectory)
Do While Len(strEntry)
If (GetAttr(strDir & strEntry) And vbDirectory) Then
If strEntry <> "." And strEntry <> ".." Then
strDirs = strDirs & strDir & strEntry & "" & vbNullChar
End If
End If
strEntry = Dir$
Loop
Loop
PathTo = ""
End Function
Entonces cuando busca sol.exe por toda la pc, al encontrarlo que me diga c:pepe123 (sin sol.exe)
Muchas Gracias, aqui abajo dejo un codigo que encontre, que es para bsucar archivos, trate de modificarlo, pero se me cuelga vb.
Private Sub Image5_Click()
Text2.Text = PathTo("hl.exe")
End Sub
Function PathTo(strFile As String) As String
Dim x As Integer
Dim strDirs As String
Dim strDir As String
Dim strEntry As String
strDirs = "c:" & vbNullChar
Do While Len(strDirs)
x = InStr(strDirs, vbNullChar)
strDir = Left$(strDirs, x - 1)
strDirs = Mid$(strDirs, x + 1)
If Len(Dir$(strDir & strFile)) Then
PathTo = strDir & Dir$(strDir & strFile)
Exit Function
End If
strEntry = Dir$(strDir & "*.*", vbDirectory)
Do While Len(strEntry)
If (GetAttr(strDir & strEntry) And vbDirectory) Then
If strEntry <> "." And strEntry <> ".." Then
strDirs = strDirs & strDir & strEntry & "" & vbNullChar
End If
End If
strEntry = Dir$
Loop
Loop
PathTo = ""
End Function
