VBS打開當前腳本所在文件夾
方法一:Wscript.ScriptFullName
'創(chuàng)建一個 Wscript.Shell 對象的實例,稍后會使用這個對象啟動 Windows 資源管理器
Set objShell = CreateObject("Wscript.Shell")
'獲取腳本的路徑
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
'獲取腳本當前所在文件夾的路徑
strFolder = objFSO.GetParentFolderName(objFile)
strPath = "explorer.exe /e," & strFolder
'啟動 Windows 資源管理器,打開腳本所在的文件夾
objShell.Run strPath
方法二:objShell.CurrentDirectory
這種方法代碼少了一些
set objShell = CreateObject("Wscript.Shell")
'腳本的當前目錄
strPath = objShell.CurrentDirectory
strPath = "explorer.exe /e," & strPath
objShell.Run strPath
下面是本站小編的補充
如果是腳本中需要調(diào)用下面很簡單的一句話就可以獲取當前目錄
currentpath = createobject("Scripting.FileSystemObject").GetFolder(".").Path
或
currentpath = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
是不是更簡單呢,這篇文章就分享到這了,希望大家以后多多支持本站。
版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信