♣
如何使用文件选择框来取得文件路径?
我想实现的是,按下一个按钮,然后弹出一个文件选择框(就是选择一个文件作用的),比如返回的一个值"c:\abcd\1234.exe",有什么办法可以从中取得"c:\abcd\"?
· 网友精彩回答:
也可以直接选择需要文件的父文件夹
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 browseforfolder(hwndowner as long, sprompt as string) as string
declare variables to be used
dim inull as integer
dim lpidlist as long
dim lresult as long
dim spath as string
dim udtbi as browseinfo
initialise variables
with udtbi
.hwndowner = hwndowner
.lpsztitle = lstrcat(sprompt, "")
.ulflags = bif_returnonlyfsdirs
.pidlroot = 0&
end with
call the browse for folder api
lpidlist = shbrowseforfolder(udtbi)
get the resulting string path
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
if cancel was pressed, spath = ""
browseforfolder = spath
end function
可以参考:
http://dev.csdn.net/develop/article/27/27156.shtm
private sub command1_click()
dim x() as string 定义动态数组
commondialog1.showopen
file_name = commondialog1.filename
x = split(file_name, "\") 以"\"分隔
n = ubound(x)
redim preserve x(n - 1) 数组下标减少1
file_path = join(x, "\") 合并
msgbox "文件的路径是:" & vbcrlf & file_path
end sub
msgbox mid("c:\abcd\1234.exe", 1, instrrev("c:\abcd\1234.exe", "\"))
或
dim str as string
str = "c:\abcd\1234.exe"
msgbox mid(str, 1, instrrev(str, "\"))
- 更多问题:
- · 高分求两计算机连接问题
- · 达赖喇嘛表示愿意有条件放弃“达赖”的头衔
- · 传巨浪二型导弹成功发射 具二次核打击能力
- · windows为什么要使用消息循环
- · 博士街头当乞丐?
- · 标题有点那个,还是不写了吧
- · 日本处于“对华心理调适期”
- · 中国政改的困难(摘自《早报网》)
- · 如何在一个程序中实现“当程序被人从进程列表中强行结束就执行一段特定得代码(如写错误日志)”在线等待。。。
- · 谁会用dev-c++添加音乐???
- · 如何使img不响应双击事件?
- · 有关GDI+的简单问题
- · 求碰撞代码
- · 数据库的备份与回复(拆分与合并),教教我吧
- · CSDN首页的那个“文档”有没有搜索功能啊?
- · 郁闷啊,每次提交保存竟然永遠是同樣的時間,連<F5>刷新都沒用!
- · 权限设置与技术
- · style样式 | style
- · 字符相关问题
- · 缓存技术应用
- · Session技术文档 | Session
- · Application技术文档
- · ntfs文件
- · 入侵xp
- · 改mac
- · serv u3.0
- · dns服务
- · mac mini
- · pdf转换工具
- · borland starteam
- · bios升级
- · php后门
- · 我电脑中木马了!可是木马助手和瑞星杀毒查不出来?_百度知道
- · 梦幻西游木马
- · 一句话木马
- · 查杀木马工具哪个最好
- · 免费木马
- · 什么是黑客,有什么用途??
- · 网吧黑客常用手法
- · 中美黑客大战
- · firefox

