You are here:

Visual Basic/path of the selected folder

Advertisement


Question
i have created an application where if i rightclick on a folder an option appears where my form gets loaded.
i need to get the full path of this folder in my application.
i tried

Environment.CurrentDirectory

but it only shows the opened directory path and not the path of the selected item in it.

Answer
you need to assign it. since i dont know your code cannot comment.

to get the path use this method
   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:\icons3\apple.ico"
   Debug.Print pathOfFile(myPath)
   Debug.Print pathOfFile(myPath) & "apple.ico"
End Sub

Visual Basic

All Answers


Answers by Expert:


Ask Experts

Volunteer


Ravindra

Expertise

visual basic application programming from design to access information, sql, engineering and commercial applications. access databases, excel.(VB6) basic questions in vb 2008. Optional: 1)a large number of people want me to do work which takes some time and effort. can do projects in vb 2008. Pl.note that i would like to be paid for such work. 2) if you want me to spend quality time and do special work, i expect to be paid a reasonable price for my time. 3) if you are pleased with my reply you could consider a good amount. 4) you can visit my website http://ravindra.coolpage.biz

Experience

programming since the past 15 years. have completed a large number of projects in Industrial applications, finance,accounts, correspondence. excel macros etc

Education/Credentials
engineering, management degrees.

Past/Present Clients
project work for a Norway company,USA company and a Canadian company completed. Freelance Project work and Teaching. helping programmers with their work
teaching vb

©2016 About.com. All rights reserved.