VBS打开显示当前脚本所在文件夹
原创
©著作权归作者所有:来自51CTO博客作者王大师王文峰的原创作品,请联系作者获取转载授权,否则将追究法律责任
方法一:Wscript.ScriptFullName
'创建一个 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