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

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

Jx Man your the man cheers

commented: Your signature hurts me! -3

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.