收藏 分享(赏)

VB获取文件夹路径-新建【文件】和【文件夹】.doc

上传人:dzzj200808 文档编号:2256436 上传时间:2018-09-07 格式:DOC 页数:4 大小:50.50KB
下载 相关 举报
VB获取文件夹路径-新建【文件】和【文件夹】.doc_第1页
第1页 / 共4页
VB获取文件夹路径-新建【文件】和【文件夹】.doc_第2页
第2页 / 共4页
VB获取文件夹路径-新建【文件】和【文件夹】.doc_第3页
第3页 / 共4页
VB获取文件夹路径-新建【文件】和【文件夹】.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、VB 浏览文件夹获取文件夹路径2011-10-24 11:11提问者: 羊岔路 | 浏览次数: 1446 次我编写了一个小程序,程序下有个 file 文件夹,里面有很多文件,程序运行时我会根据条件选择出一部分文件,但是程序只能选择出文件名,我希望能够将我选择出的文件名对应的文件拷贝出来,拷贝的目标文件夹由我通过浏览文件夹指定,初步想通过Commanddialog 来实现,我该怎么写代码?问题补充:能不能在浏览出来的文件夹中让用户自己新建文件夹,就像我们有时安装程序那样!我来帮他解答满意回答commondialog 控件只能选择文件,不能选择文件夹,用下面的代码可以选文件夹:Option Exp

2、licitPrivate Type BrowseInfohWndOwner As LongpIDLRoot As LongpszDisplayName As LonglpszTitle As LongulFlags As LonglpfnCallback As LonglParam As LongiImage As LongEnd TypeConst BIF_RETURNONLYFSDIRS = 1Const MAX_PATH = 260Private Declare Sub CoTaskMemFree Lib “ole32.dll“ (ByVal hMem As Long)Private D

3、eclare Function lstrcat Lib “kernel32“ Alias “lstrcatA“ (ByVal lpString1 As String, ByVal lpString2 As String) As LongPrivate Declare Function SHBrowseForFolder Lib “shell32“ (lpbi As BrowseInfo) As LongPrivate Declare Function SHGetPathFromIDList Lib “shell32“ (ByVal pidList As Long, ByVal lpBuffer

4、 As String) As LongPublic Function BrowseForFolder(Optional sTitle As String = “请选择文件夹“) As StringDim iNull As Integer, lpIDList As Long, lResult As LongDim sPath As String, udtBI As BrowseInfoWith udtBI.hWndOwner = 0 Me.hWnd.lpszTitle = lstrcat(sTitle, “).ulFlags = BIF_RETURNONLYFSDIRSEnd WithlpIDL

5、ist = SHBrowseForFolder(udtBI)If lpIDList ThensPath = String$(MAX_PATH, 0)SHGetPathFromIDList lpIDList, sPathCoTaskMemFree lpIDListiNull = InStr(sPath, vbNullChar)If iNull ThensPath = Left$(sPath, iNull - 1)End IfEnd IfBrowseForFolder = sPathEnd FunctionPrivate Sub Command1_Click()MsgBox BrowseForFo

6、lder()End Sub追问谢谢!这个可以实现,再问下,能不能在浏览出来的文件夹中让用户自己新建【文件夹】 ,就像我们有时安装程序那样!回答Option ExplicitPrivate Type BrowseInfohWndOwner As LongpIDLRoot As LongpszDisplayName As LonglpszTitle As LongulFlags As LonglpfnCallback As LonglParam As LongiImage As LongEnd TypeConst BIF_RETURNONLYFSDIRS = 1Const BIF_NEWDIALO

7、GSTYLE = &H40Const BIF_EDITBOX = &H10Const BIF_USENEWUI = BIF_NEWDIALOGSTYLE Or BIF_EDITBOXConst 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)

8、 As LongPrivate Declare Function SHBrowseForFolder Lib “shell32“ (lpbi As BrowseInfo) As LongPrivate Declare Function SHGetPathFromIDList Lib “shell32“ (ByVal pidList As Long, ByVal lpBuffer As String) As LongPublic Function BrowseForFolder(Optional sTitle As String = “请选择文件夹“) As StringDim iNull As

9、 Integer, lpIDList As Long, lResult As LongDim sPath As String, udtBI As BrowseInfoWith udtBI.hWndOwner = 0 Me.hWnd.lpszTitle = lstrcat(sTitle, “).ulFlags = BIF_RETURNONLYFSDIRS Or BIF_USENEWUIEnd WithlpIDList = SHBrowseForFolder(udtBI)If lpIDList ThensPath = String$(MAX_PATH, 0)SHGetPathFromIDList

10、lpIDList, sPathCoTaskMemFree lpIDListiNull = InStr(sPath, vbNullChar)If iNull ThensPath = Left$(sPath, iNull - 1)End IfEnd IfBrowseForFolder = sPathEnd FunctionPrivate Sub Command1_Click()MsgBox BrowseForFolder()End Sub提问者对回答的评价:写得太好了,我从昨天晚上开始找一直都没有找到可用的代码,非常感谢呵呵, xjnzhidao 方法非常好!至于你要实现新建 【文件 】的功能,把 xjnzhidao 的代码作如下更改:With udtBI.hWndOwner = 0 Me.hWnd.lpszTitle = lstrcat(sTitle, “).ulFlags = BIF_RETURNONLYFSDIRSEnd With改:With udtBI.hWndOwner = 0 Me.hWnd.lpszTitle = lstrcat(sTitle, “).ulFlags =99-这里是更改的地方End With 1| 评论等待您来回答

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报