Du kan lægge disse funktioner i et modul: Function FindFiler(strFilename As String, strDrive As String, Optional ReturnAll As Boolean = True) As String
Dim varItm As Variant Dim strFiles As String Dim strTmp As String Dim strResult As String
If InStr(strFilename, ".") = 0 Then MsgBox "Du skal angive hele filnavnet!", vbCritical, "Extension mangler!" Exit Function End If If InStr(strDrive, ":") = 0 And Len(strDrive) = 1 Then strDrive = strDrive & ":" End If
With Application.FileSearch .NewSearch .LookIn = strDrive .SearchSubFolders = True .FileName = strFilename .MatchTextExactly = True .FileType = 2 'msoFileTypeAllFiles If .Execute > 0 Then For Each varItm In .FoundFiles strTmp = ExtractFileName(varItm) If strFilename = strTmp Then If ReturnAll Then strResult = strResult & varItm & ";" Else FindFiler = varItm Exit Function End If End If Next varItm strResult = Left(strResult, Len(strResult) - 1) FindFiler = strResult End If End With End Function
Private Function ExtractFileName(strFullPath) As String Dim intPos As Integer, intLen As Integer intLen = Len(strFullPath) If intLen Then For intPos = intLen To 1 Step -1 'Find the last \ If Mid$(strFullPath, intPos, 1) = "\" Then ExtractFileName = Mid$(strFullPath, intPos + 1) Exit Function End If Next intPos End If End Function
Herefter kan du finde filen således FindFiler("winamp.exe ", "C:", false)
Private Declare Function SearchTreeForFile Lib "imagehlp" (ByVal RootPath As String, ByVal InputPathName As String, ByVal OutputPathBuffer As String) As Long Private Const MAX_PATH = 260
Private Sub Form_Load() Dim strTemp As String
strTemp = String(MAX_PATH, 0) If SearchTreeForFile("C:\", "winamp.exe", strTemp) <> 0 Then MsgBox Left$(strTemp, InStr(1, strTemp, Chr$(0)) - 1) Else MsgBox "File not found!" End If End Sub '--------------------------------------- Form1 ---------------------------------------
ehhhh, tak for aktiviteten drenge, men mente nu at den også skulle åbne programmet og helst ikke nogen msgbox'ses den ska bar eåbne programmet :) på forhånd tak
Private Declare Function SearchTreeForFile Lib "imagehlp" (ByVal RootPath As String, ByVal InputPathName As String, ByVal OutputPathBuffer As String) As Long Private Const MAX_PATH = 260
Private Sub Form_Load() Dim strTemp As String
strTemp = String(MAX_PATH, 0) If SearchTreeForFile("C:\", "winamp.exe", strTemp) <> 0 Then Call Shell(Left$(strTemp, InStr(1, strTemp, Chr$(0)) - 1), vbNormalFocus) End If End Sub '--------------------------------------- Form1 ---------------------------------------
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.