获取vbscript中的当前目录 [英] getting current directory in vbscript

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

问题描述

我试图获取当前目录并使用它来运行应用程序,无论文件放在哪里,无论路径如何更改。

im 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 = CurrentDirectory\attribute.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? Thanks in advance!

推荐答案

如果要从变量和文件名构建路径,名称必须指定为字符串(或包含字符串的变量),并连接到变量目录变量:

If you want to build a path from a variable and a file name, the file name must be specified as a string (or a variable containing a string) and either concatenated with the variable directory variable:

Directory = CurrentDirectory & "\attribute.exe"

或(更好)您使用 BuildPath 方法:

or (better) you construct the path using the BuildPath method:

Directory = fso.BuildPath(CurrentDirectory, "attribute.exe")

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

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