Èí¼þ¿ª·¢Åàѵ°à >> ±à³Ì¿ª·¢ >> VbScript
使用VBS�览本地文件��方�,获�完整路径 |
|
¡¡¡¡±¾ÎıêÇ©£ºVBSæµ�览本地文件 å› ä¸ºç³»ç»Ÿç»„ä»¶å·®å¼‚ï¼Œæ‰€ä»¥ä»£ç �也有ä¸�å�Œæ–‡ç« 最å�Žè„šæœ¬ä¹‹å®¶ç»™å‡ºä¸€ä¸ªé€šç”¨çš„ä»£ç ?/p> 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
BrowseForFile
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
BrowseForFile
有没有å�‘现上é�¢çš„代ç �è¿�行ä¸�易啊,这里脚本之家å°�编为大家分享一个å�¯ç”¨çš„,虽然上é�¢çš„的代ç �ä¸�能用但å¦ä¹ å�‚考一下还是ä¸�é”™çš„ï¼ŒçŽ°åœ¨å› ä¸ºå¹³å�°æ„¿æ„�导致,原æ�¥è¿™äº›ä»£ç �都是å�¯ä»¥ä½¿ç”¨çš„ã€?/p>
Function ChooseFile()
Dim Result
Result = ""
Dim IE : Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = False
.Navigate("about:blank")
Do Until .ReadyState = 4 : Loop
With .Document
.Write "<html><body><input id='f' type='file'></body></html>"
With .All.f
.Focus
.Click
Result = .Value
End With
End With
.Quit
End With
Set IE = Nothing
ChooseFile = Result
End Function
ChooseFile
好了这篇 关于vbs选择本地文件功能的代ç �就介ç»�到这了,需è¦�的朋å�‹å�¯ä»¥å�‚考一下ã€?/p> |