We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,695 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to open a folder with a file path vb 6

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

4
Contributors
6
Replies
1 Week
Discussion Span
1 Year Ago
Last Updated
7
Views
Question
Answered
razamughal67
Junior Poster in Training
82 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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
Senior Poster
3,521 posts since Nov 2007
Reputation Points: 1,468
Solved Threads: 514
Skill Endorsements: 64

Jx Man your the man cheers

androidz
Junior Poster
158 posts since Aug 2010
Reputation Points: 8
Solved Threads: 3
Skill Endorsements: 0

Hi,

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

Regards
Veena

QVeen72
Veteran Poster
1,017 posts since Nov 2006
Reputation Points: 118
Solved Threads: 164
Skill Endorsements: 5

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 ?

razamughal67
Junior Poster in Training
82 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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
Jx_Man
Senior Poster
3,521 posts since Nov 2007
Reputation Points: 1,468
Solved Threads: 514
Skill Endorsements: 64

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

razamughal67
Junior Poster in Training
82 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Jx_Man, QVeen72 and androidz

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0706 seconds using 2.64MB