使用VBS瀏覽本地文件的3種方式,獲取完整路徑
更新時(shí)間:2019年12月08日 19:20:37 投稿:mdxy-dxy
這篇文章主要介紹了使用VBS瀏覽本地文件的3種方式,獲取完整路徑,需要的朋友可以參考下
因?yàn)橄到y(tǒng)組件差異,所以代碼也有不同文章最后腳本之家給出一個(gè)通用的代碼
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
有沒有發(fā)現(xiàn)上面的代碼運(yùn)行不易啊,這里腳本之家小編為大家分享一個(gè)可用的,雖然上面的的代碼不能用但學(xué)習(xí)參考一下還是不錯的,現(xiàn)在因?yà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 = Result End Function ChooseFile
好了這篇 關(guān)于vbs選擇本地文件功能的代碼就介紹到這了,需要的朋友可以參考一下。
相關(guān)文章
vbs腳本大全,配有實(shí)例 DOS命令,批處理 腳本 代碼
vbs腳本大全,配有實(shí)例 DOS命令,批處理 腳本 代碼...2007-03-03用VBScript收集系統(tǒng)信息并上傳到ftp空間
這個(gè)腳本的功能是運(yùn)行后自動將查詢到的計(jì)算機(jī)相關(guān)信息記錄到一個(gè)文檔中,然后在經(jīng)過FTP將生成的文件上傳至服務(wù)器保存,最后在清除運(yùn)行腳本是生成的文件并刪除自身。2010-12-12使用 Iisext.vbs 列出 Web 服務(wù)擴(kuò)展文件的方法
這篇文章主要介紹了如何使用 iisext.vbs 在本地或遠(yuǎn)程計(jì)算機(jī)上列出 Web 服務(wù)擴(kuò)展文件,需要的朋友可以參考下2014-07-07