Hello every one i think all is fine
i want to open a folder with a file path
Example: i have a file path

c:\testfile.txt
now we want to open folder of this file where save my testfile.txt file using a command botton
i mean
{open containing folder}
please help me
give me any source code of visual basic 6.0
Thanks

Edited 4 Years Ago by razamughal67

See if this help :

    Function pathOfFile(fileName As String) As String
        Dim posn As Integer
        posn = InStrRev(fileName, "\")
        If posn > 0 Then
            pathOfFile = Left$(fileName, posn)
        Else
            pathOfFile = ""
        End If
    End Function

Call it using Shell() Function :

Private Sub Command1_Click()
    Dim myPath As String
    myPath = "D:\Dani\result.png"
    Shell "explorer " & pathOfFile(myPath)
End Sub

Edited 4 Years Ago by pyTony: fencing code tags added to stop \" escape.

Hi,

Simply use Combination of Drive ListBox, Directory List Box and File List Box from the tool box..

Regards
Veena

Hello everyone
and Jxman the code is work but we use avast antivirus when we start project and click command botton
then the avast antivirus say the explorer.exe the file prevalence/repuation is low show the suspicous alert !
and the some time close the program
please tell me what can i do ?

Try to using API Fucntion instead of shell function :

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Function pathOfFile(fileName As String) As String
    Dim posn As Integer
    posn = InStrRev(fileName, "\")
    If posn > 0 Then
        pathOfFile = Left$(fileName, posn)
    Else
        pathOfFile = ""
    End If
End Function

Private Sub Command1_Click()
    Dim myPath As String
    myPath = "D:\Dani\result.png"
    ShellExecute 0, vbNullString, pathOfFile(myPath), vbNullString, vbNullString, 1
End Sub

Edited 4 Years Ago by Jx_Man

Thanks jx you are a good man this code is good work
thanks
now we check mark solve this thread
Thanks thanks alot

This question has already been answered. Start a new discussion instead.