VB6中获取选定文件夹的路径
我想获取选定的文件夹路径
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
这显示输出“C:\ MRMS \ Report \ xyz.txt”,但我只想要选定的文件夹路径,即如果用户仅选择根(MRMS ) 文件夹,即
"C:\MRMS"
或任何其他文件夹(仅限用户选择的文件夹)。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最短路线:
The shortest way:
试试这个
然后,在您的代码中,引用这样的函数...
Try this
Then, in your code, reference the function like this...
通过通用对话查找所选文件的文件夹的另一种方法是:
An alternative way to find the folder of selected file by Common Dialogue is this:
这是 VB5 的一个简单的基本解决方案,它没有 Split 函数:
Here's a simple bare-bones solution for VB5 which doesn't have the Split function: