VBS打开当前脚本所在文件夹
时间:2021-01-15 11:13:01|栏目:VBS|点击: 次
方法一: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
如果是脚本中需要调用下面很简单的一句话就可以获取当前目录
currentpath = createobject("Scripting.FileSystemObject").GetFolder(".").Path
或
currentpath = createobject("Scripting.FileSystemObject").GetFile(Wscript.ScriptFullName).ParentFolder.Path
上一篇:支持断点下载的VBS代码
栏 目:VBS
下一篇:vbs 列出该目录下所有文件和文件夹的类型,大小,和所有者
本文标题:VBS打开当前脚本所在文件夹
本文地址:http://www.codeinn.net/misctech/45466.html






