方法一:Wscript.ScriptFullName
'創(chuàng)建一個(gè) Wscript.Shell 對(duì)象的實(shí)例,稍后會(huì)使用這個(gè)對(duì)象啟動(dòng) Windows 資源管理器
Set objShell = CreateObject("Wscript.Shell")
'獲取腳本的路徑
strPath = Wscript.ScriptFullName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(strPath)
'獲取腳本當(dāng)前所在文件夾的路徑
strFolder = objFSO.GetParentFolderName(objFile)
strPath = "explorer.exe /e," strFolder
'啟動(dòng) Windows 資源管理器,打開(kāi)腳本所在的文件夾
objShell.Run strPath
方法二:objShell.CurrentDirectory
這種方法代碼少了一些
set objShell = CreateObject("Wscript.Shell")
'腳本的當(dāng)前目錄
strPath = objShell.CurrentDirectory
strPath = "explorer.exe /e," strPath
objShell.Run strPath
下面是腳本之家小編的補(bǔ)充
如果是腳本中需要調(diào)用下面很簡(jiǎn)單的一句話就可以獲取當(dāng)前目錄
currentpath = createobject("Scripting.FileSystemObject").GetFolder(".").Path
或
currentpath = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
是不是更簡(jiǎn)單呢,這篇文章就分享到這了,希望大家以后多多支持腳本之家。
您可能感興趣的文章:- vbs中獲取腳本當(dāng)前路徑的2個(gè)方法
- 用vbs實(shí)現(xiàn)在啟動(dòng) Windows 資源管理器時(shí)打開(kāi)特定文件夾