国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

使用VBS瀏覽本地文件的3種方式,獲取完整路徑

2020-07-26 11:19:44
字體:
供稿:網(wǎng)友

因為系統(tǒng)組件差異,所以代碼也有不同文章最后武林網(wǎng)給出一個通用的代碼

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.ShowOpenIf intResult <> 0 Then	BrowseForFile = objDialog.FileName	exit functionelse	msgbox "Error."End Ifend functionBrowseForFile

2003下'for windows 2003

Function SelectAFileSet objDialog = CreateObject("SAFRCFileDlg.FileOpen")intResult = objDialog.OpenFileOpenDlgSelectAFile = objDialog.FileNameEnd Function

瀏覽器方式:

Function BrowseForFile( ) '===========2, fileselect in IE ======================  'Another way to get file path  Dim objIE, strSelected  BrowseForFile = ""  Set objIE = CreateObject( "InternetExplorer.Application" )objIE.ToolBar = FalseobjIE.Resizable = FalseobjIE.StatusBar = False objIE.Width = 300objIE.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 = strSelectedEnd FunctionBrowseForFile

有沒有發(fā)現(xiàn)上面的代碼運行不易啊,這里武林網(wǎng)小編為大家分享一個可用的,雖然上面的的代碼不能用但學(xué)習(xí)參考一下還是不錯的,現(xiàn)在因為平臺愿意導(dǎo)致,原來這些代碼都是可以使用的。

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 = ResultEnd FunctionChooseFile

好了這篇 關(guān)于vbs選擇本地文件功能的代碼就介紹到這了,需要的朋友可以參考一下。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 广汉市| 马公市| 绥棱县| 昌宁县| 唐海县| 大丰市| 县级市| 青河县| 南城县| 石渠县| 潞西市| 定州市| 喀什市| 大关县| 哈尔滨市| 镇赉县| 陈巴尔虎旗| 建德市| 深水埗区| 陆川县| 滦南县| 金山区| 西平县| 北碚区| 周宁县| 宁强县| 卓尼县| 万州区| 大余县| 邢台县| 抚州市| 伊宁县| 大埔县| 大丰市| 水富县| 白银市| 洪洞县| 瓦房店市| 孝感市| 成都市| 蒙阴县|