方法一:Wscript.ScriptFullName
'創建一個 Wscript.Shell 對象的實例,稍后會使用這個對象啟動 Windows 資源管理器Set objShell = CreateObject("Wscript.Shell")'獲取腳本的路徑strPath = Wscript.ScriptFullNameSet 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.CurrentDirectorystrPath = "explorer.exe /e," & strPathobjShell.Run strPath
下面是武林網小編的補充
如果是腳本中需要調用下面很簡單的一句話就可以獲取當前目錄
currentpath = createobject("Scripting.FileSystemObject").GetFolder(".").Path
或
currentpath = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
是不是更簡單呢,這篇文章就分享到這了,希望大家以后多多支持武林網。
新聞熱點
疑難解答