在 VBScript 中获取当前目录 [英] Getting current directory in VBScript

查看:23
本文介绍了在 VBScript 中获取当前目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取当前目录并使用它来运行应用程序,无论文件放在何处,也无论路径如何更改

I'm trying to get the current directory and use it to run an application no matter where the file is put and no matter how the path is changed

Dim fso: set fso = CreateObject("Scripting.FileSystemObject")
Dim CurrentDirectory
CurrentDirectory = fso.GetAbsolutePathName(".")
Dim Directory
Directory = CurrentDirectoryattribute.exe

Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "Directory" & Chr(34), 0
Set WinScriptHost = Nothing

我实际上如何设置此代码以使其正确执行我希望它执行的操作?

How do I actually set up this code so it does what I want it to do correctly?

推荐答案

您可以使用 WScript.ScriptFullName 返回执行脚本的完整路径.


然后您可以使用字符串操作(jscript 示例):

scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1)


或者从 FileSystemObject 获取帮助,(vbscript 示例):

scriptdir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)

这篇关于在 VBScript 中获取当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆