建议改用DriveListBox+DirListBox+FileListBox
解决方案 »
- 求大神来看看这是怎么写的
- vb如何 检测文本框输入的是否为字母或数字~~
- 代码没有错,询问红色部分中的check和index分别代表什么?此程序是实现记忆翻牌游戏,若2个图片相同就翻纸牌,否则变为背景图片
- CreateObject("WMPlayer.OCX") 怎么遇到11版就不行了? (在线等,VB6)
- 如何使用spl语句实现表中某字段数据的更新?
- 在VB6里怎样用ADO获取ORACLE9的存储过程或函数的结果集
- 为什么mciSendString不能播放中文文件名的MP3啊?
- 编程之余轻松一下,给大家推荐一个免费的电影网!!
- flexcell问题
- 有关向word文档中写数据的问题
- 抓图(mpeg、asf、wav、rm等)
- 请各位高手指点如何写库存管理程序?
mid(cd.filename,1,len(cd.filename)-len(cd.filetitle)-1)
自己再调一调,就是找到Filename中的文件名,再剔除来就行了
Dim FPath As String
DirPath = ""
DirPath = BrowseForFolder(Me.hwnd, "选择一个 Mp3 目录。")
If DirPath = "" Then Exit Sub ’写你 处理 DirPath的代码!!!
end sub'在模块中 :Option Explicitpublic DirPath As String
public InifilePath As StringPrivate 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 TypePrivate Const BIF_RETURNONLYFSDIRS = 1
Private Const MAX_PATH = 260Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" _
(ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32" _
(lpBI As BrowseInfo) As LongPrivate Declare Function SHGetPathFromIDList Lib "shell32" _
(ByVal pidList As Long, ByVal lpBuffer As String) As Long
'函数:Public Function BrowseForFolder(hWndOwner As Long, sPrompt As String) As String Dim iNull As Integer
Dim lpIDList As Long
Dim lResult As Long
Dim sPath As String
Dim udtBI As BrowseInfo
With udtBI
.hWndOwner = hWndOwner
.lpszTitle = lstrcat(sPrompt, "")
.ulFlags = BIF_RETURNONLYFSDIRS
End With
lpIDList = SHBrowseForFolder(udtBI)
If lpIDList Then
sPath = String$(MAX_PATH, 0)
lResult = SHGetPathFromIDList(lpIDList, sPath)
Call CoTaskMemFree(lpIDList)
iNull = InStr(sPath, vbNullChar)
If iNull Then
sPath = Left$(sPath, iNull - 1)
End If
End If
BrowseForFolder = sPathEnd Function
'在工程中新建模块如下
Option ExplicitPublic 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 TypePublic Const BIF_RETURNONLYFSDIRS = 1
Public Const MAX_PATH = 260Public 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 LongPublic Function BrowseForFolder(hwndOwner As Long, sPrompt As String) As String
'声明变量类型
Dim iNull As Integer
Dim lpIDList As Long
Dim lResult As Long
Dim sPath As String
Dim udtBI As BrowseInfo '变量初始化
With udtBI
.hwndOwner = hwndOwner
.lpszTitle = lstrcat(sPrompt, "")
.ulFlags = BIF_RETURNONLYFSDIRS
End With '调用API浏览文件夹
lpIDList = SHBrowseForFolder(udtBI)
'取路径字串
If lpIDList Then
sPath = String$(MAX_PATH, 0)
lResult = SHGetPathFromIDList(lpIDList, sPath)
Call CoTaskMemFree(lpIDList)
iNull = InStr(sPath, vbNullChar)
If iNull Then sPath = Left$(sPath, iNull - 1)
End If '按取消键返回空字符串
BrowseForFolder = sPathEnd Function
'-------------------------------
'在需要调用的地方使用如下方法
StrFoldername$ = BrowseForFolder(hWnd, "对话框标题")
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End TypeConst BIF_RETURNONLYFSDIRS = &H1Private pidl As LongPrivate Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, ByVal pszPath As String) As LongPrivate Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As LongPrivate Sub command1_Click()
Dim bi As BROWSEINFO
Dim r As Long
Dim pidl As Long
Dim path As String
Dim pos As Integer
'句柄
bi.hOwner = Me.hWnd
'展开根目录
bi.pidlRoot = 0&
'列表框标题
bi.lpszTitle = "请选择文件夹:"
'规定只能选择文件夹,其他无效
bi.ulFlags = BIF_RETURNONLYFSDIRS
'调用API函数显示列表框
pidl = SHBrowseForFolder(bi)
'利用API函数获取返回的路径
path = Space$(512)
r = SHGetPathFromIDList(ByVal pidl&, ByVal path)
If r Then
pos = InStr(path, Chr$(0))
Text1.Text = Left(path, pos - 1)
Command2.Enabled = True
Else
Text1.Text = ""
Command2.Enabled = False
End If
End Sub
而且还能锻炼API的应用能力!