vb中在文本框里显示选中的文件夹路径
我做了一个备份的窗体,“备份至”后边有一个文本框浏览选择一个文件夹,在文本框中显示该文件夹的路径(是文件夹不是文件),代码怎么写呢?还有就是备份和恢复的代码最好也能写出来...
我做了一个备份的窗体,“备份至”后边有一个文本框 浏览选择一个文件夹,在文本框中显示该文件夹的路径(是文件夹不是文件),代码怎么写呢?还有就是备份和恢复的代码最好也能写出来!谢谢各位了!
展开
3个回答
展开全部
Private Sub Command1_Click()
'引用 Microsoft Shell Controls And Automation
Const BIF_EDITBOX = &H10
Const BIF_STATUSTEXT = &H4
Const BIF_RETURNFSANCESTORS = &H8
Const BIF_VALIDATE = &H20
Const BIF_BROWSEFORCOMPUTER = &H1000
Const BIF_RETURNONLYFSDIRS = 1
Const BIF_DONTGOBELOWDOMAIN = 2
Dim x As New Shell32.Shell
Dim y As Shell32.Folder
Set y = x.BrowseForFolder(Me.hWnd, "aa", 1)
'法1:
If Not y Is Nothing Then
MsgBox y.ParentFolder.ParseName(y.Title).Path
End If
'====================================
'法2:
If Not y Is Nothing Then
Dim sFoldersPath As String
Dim sPath As String
sPath = y.Title
sFoldersPath = y.Title
Do Until y.ParentFolder Is Nothing
sFoldersPath = y.ParentFolder & "\" & sFoldersPath
If VBA.InStr(sPath, ":") = 0 Then
If Not y.ParentFolder Like "*:*" Then
sPath = y.ParentFolder & "\" & sPath
Else
sPath = VBA.Mid(y.ParentFolder, VBA.InStr(y.ParentFolder, ":") - 1, 2) & "\" & sPath
'Exit Do
End If
End If
Set y = y.ParentFolder
Loop
If VBA.Len(VBA.Trim(sPath)) > 0 Then
text1.text= sPath & vbCrLf
End If
End If
End Sub
'引用 Microsoft Shell Controls And Automation
Const BIF_EDITBOX = &H10
Const BIF_STATUSTEXT = &H4
Const BIF_RETURNFSANCESTORS = &H8
Const BIF_VALIDATE = &H20
Const BIF_BROWSEFORCOMPUTER = &H1000
Const BIF_RETURNONLYFSDIRS = 1
Const BIF_DONTGOBELOWDOMAIN = 2
Dim x As New Shell32.Shell
Dim y As Shell32.Folder
Set y = x.BrowseForFolder(Me.hWnd, "aa", 1)
'法1:
If Not y Is Nothing Then
MsgBox y.ParentFolder.ParseName(y.Title).Path
End If
'====================================
'法2:
If Not y Is Nothing Then
Dim sFoldersPath As String
Dim sPath As String
sPath = y.Title
sFoldersPath = y.Title
Do Until y.ParentFolder Is Nothing
sFoldersPath = y.ParentFolder & "\" & sFoldersPath
If VBA.InStr(sPath, ":") = 0 Then
If Not y.ParentFolder Like "*:*" Then
sPath = y.ParentFolder & "\" & sPath
Else
sPath = VBA.Mid(y.ParentFolder, VBA.InStr(y.ParentFolder, ":") - 1, 2) & "\" & sPath
'Exit Do
End If
End If
Set y = y.ParentFolder
Loop
If VBA.Len(VBA.Trim(sPath)) > 0 Then
text1.text= sPath & vbCrLf
End If
End If
End Sub
展开全部
Dim ofd As New OpenFileDialog()
ofd.Filter = "DOC Files(*.doc)|*.doc|PDF Files(*.pdf)|*.pdf|CAJ Files(*.caj)|*.caj|All Files|*.*"
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
TextBox1.Text = ofd.FileName
End If
ofd.Filter = "DOC Files(*.doc)|*.doc|PDF Files(*.pdf)|*.pdf|CAJ Files(*.caj)|*.caj|All Files|*.*"
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
TextBox1.Text = ofd.FileName
End If
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上的,你的这个是.net代码吧..
vb6的代码是,您去下载一个浏览对话框的类,就可以了!
vb6的代码是,您去下载一个浏览对话框的类,就可以了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询