Getting path of selected folder in VB6

Rameez picture Rameez · Jun 20, 2011 · Viewed 8.6k times · Source

I want to get the selected folder path

dlgBrowse.ShowOpen
fname = dlgBrowse.FileName
dlgBrowse.Filter = "Text File (*.txt)|*.txt|Log File (*.log)|*.log||All Files (*.*)|*.*"
dlgBrowse.DialogTitle = "Open Log File"
dlgBrowse.ShowOpen
If dlgBrowse.FileName <> "" Then
    txtLogFile.Text = dlgBrowse.FileName
End If
MsgBox fname

This shows the output "C:\MRMS\Report\xyz.txt", but I want only the selected folder path, ie if the user selects only root(MRMS) folder i.e. "C:\MRMS" or any other folder only up to user selected folder.

Answer

Searush picture Searush · Oct 11, 2012

The shortest way:

Dim FullPath as string, ParentFolder as string, l() as string
FullPath = "" '... Write here the path from ComDlg
l = Split(FullPath, "\")
l(UBound(l)) = ""
ParentFolder = Join(l, "\")