VB浏览文件夹

来源:百度知道 编辑:UC知道 时间:2024/05/22 06:54:09
Dim iNull As Integer, lpIDList As Long
Dim sPath As String, udtBI As BrowseInfo

With udtBI
'设置浏览窗口
.hWndOwner = Me.hWnd
'返回选中的目录
.ulFlags = BIF_RETURNONLYFSDIRS
End With

'调出浏览窗口
lpIDList = SHBrowseForFolder(udtBI)

If lpIDList Then
sPath = String$(MAX_PATH, 0)
'获取路径
SHGetPathFromIDList lpIDList, sPath
'释放内存
CoTaskMemFree lpIDList
iNull = InStr(sPath, vbNullChar)

If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If

Text1.Text = sPath
Label1.Caption = sPath

这样调出了“浏览文件夹”,把路径赋值给了sPath,并且从Text1.Text出来了,但是我又想把它赋值给MkDir "F:\MP3"中的F,也就是说,F盘符跟着sPath变量走,各位VB大兄,给点思路,100分。

'前面部分请放在模块中
Option Explicit

Public Type BrowseInfo
hwndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type

Public Const BIF_RETURNONLYFSDIRS = 1
Public Const MAX_PATH = 260

Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Public Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Public Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
Public Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long

Public Function ForFolder(hwndOwner As Long, sPrompt As String) As String

'declare variables to be