使用VBS通过3种方式浏览本地文件,获取完整路径。
2011-12-27 09:46
796 查看
XP下:
Function BrowseForFile( )
' Select File dialog based on a script by Mayayana
' Known issues:
' * Tree view always opens Desktop folder
' * In Win7/IE8 only the file NAME is returned correctly, the path returned will always be C:\fakepath\
' * If a shortcut to a file is selected, the name of that FILE will be returned, not the shortcut's
On Error Resume Next
'===========1, file browserer in XP ==================
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "txt|*.txt"
objDialog.InitialDir = "C:\"
intResult = objDialog.ShowOpen
If intResult <> 0 Then
BrowseForFile = objDialog.FileName
exit function
else
msgbox "Error."
End If
end function
2003下
'for windows 2003
Function SelectAFile
Set objDialog = CreateObject("SAFRCFileDlg.FileOpen")
intResult = objDialog.OpenFileOpenDlg
SelectAFile = objDialog.FileName
End Function
浏览器方式:
Function BrowseForFile( )
'===========2, fileselect in IE ======================
'Another way to get file path
Dim objIE, strSelected
BrowseForFile = ""
Set objIE = CreateObject( "InternetExplorer.Application" )
objIE.ToolBar = False
objIE.Resizable = False
objIE.StatusBar = False
objIE.Width = 300
objIE.Height = 100
objIE.visible = True
objIE.Navigate( "about:blank" )
Do Until objIE.ReadyState = 4
Loop
' Center the dialog window on the screen
With objIE.Document.ParentWindow.Screen
objIE.Left = (.AvailWidth - objIE.Width ) \ 4
objIE.Top = (.Availheight - objIE.Height) \ 4
End With
objIE.Document.Write "<HTML><BODY><INPUT ID=""FileSelect"" NAME=""FileSelect"" TYPE=""file""><BODY></HTML>"
With objIE.Document.all.FileSelect
.focus
.click
strSelected = .value
End With
objIE.Quit
Set objIE = Nothing
If Trim(strSelected) = "" Then
Msgbox "You selected no file."
Wscript.Quit
End If
BrowseForFile = strSelected
End Function
Function BrowseForFile( )
' Select File dialog based on a script by Mayayana
' Known issues:
' * Tree view always opens Desktop folder
' * In Win7/IE8 only the file NAME is returned correctly, the path returned will always be C:\fakepath\
' * If a shortcut to a file is selected, the name of that FILE will be returned, not the shortcut's
On Error Resume Next
'===========1, file browserer in XP ==================
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "txt|*.txt"
objDialog.InitialDir = "C:\"
intResult = objDialog.ShowOpen
If intResult <> 0 Then
BrowseForFile = objDialog.FileName
exit function
else
msgbox "Error."
End If
end function
2003下
'for windows 2003
Function SelectAFile
Set objDialog = CreateObject("SAFRCFileDlg.FileOpen")
intResult = objDialog.OpenFileOpenDlg
SelectAFile = objDialog.FileName
End Function
浏览器方式:
Function BrowseForFile( )
'===========2, fileselect in IE ======================
'Another way to get file path
Dim objIE, strSelected
BrowseForFile = ""
Set objIE = CreateObject( "InternetExplorer.Application" )
objIE.ToolBar = False
objIE.Resizable = False
objIE.StatusBar = False
objIE.Width = 300
objIE.Height = 100
objIE.visible = True
objIE.Navigate( "about:blank" )
Do Until objIE.ReadyState = 4
Loop
' Center the dialog window on the screen
With objIE.Document.ParentWindow.Screen
objIE.Left = (.AvailWidth - objIE.Width ) \ 4
objIE.Top = (.Availheight - objIE.Height) \ 4
End With
objIE.Document.Write "<HTML><BODY><INPUT ID=""FileSelect"" NAME=""FileSelect"" TYPE=""file""><BODY></HTML>"
With objIE.Document.all.FileSelect
.focus
.click
strSelected = .value
End With
objIE.Quit
Set objIE = Nothing
If Trim(strSelected) = "" Then
Msgbox "You selected no file."
Wscript.Quit
End If
BrowseForFile = strSelected
End Function
相关文章推荐
- VS2008 VC 如何把图片等资源文件通过本地路径加载方式加载
- 通过快捷方式获取文件路径
- 通过注册表以及文件操作的方式获取当前正在实际使用的物理网卡MAC地址
- android, 删除SD卡音乐文件。通过getContentResolver读取音乐文件,可以获取到一个完整的路径,直接new File(这括号写获取的路径).delete();
- 获取/使用偏好设置文件共有3种方式
- "打开方式"打开本地文件,获取文件路径
- [总结]Android 获取本地视频文件路径并播放的几种方式
- Atitit,通过pid获取进程文件路径 java php c#.net版本大总结
- 通过Ajax方式上传文件,使用FormData进行Ajax请求
- Hibernate通过配置文件构建org.hibernate.Session对象的方式与使用范例源代码
- C#使用单例模式类获取本地程序目录下XML文件中的配置信息
- C# 通过文件路径获取文件名、扩展名等
- 通过JS获取文件上传路径
- java中通过文件路径获取文件名
- 通过AIR获取本地配置文件
- 通过NSBundle获取文件路径的细节问题
- Android获取指定路径的图片(通过Drawable方式)
- unity3D 编辑器通过拖拽获取文件路径
- 使用GetModuleFileName()获取当前.exe所在绝对路径,并且读取.ini配置文件
- springMVC 获取本地项目路径 以及上传文件的方法整理