VBScript 宏 getParentFolder 名称 [英] VBScript Macro getParentFolder Name

查看:21
本文介绍了VBScript 宏 getParentFolder 名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 vbscript 宏,它将获取存储宏的文件夹位置并将输出文件创建到同一文件夹中.我正在使用下面的代码,但它没有得到正确的位置

I am trying to create a vbscript macro which would get the folder location in which the macro is stored and create the output files into the same folder. I am using the below code but its not getting the correct location

Set obj1FSO = CreateObject("Scripting.FileSystemObject")
folderLoc = obj1FSO.GetParentFolderName("\Cubes_Macro_V5.zmc") 

然后它将使用 folderLoc 变量并将输出文件名附加到它,以便在与存储宏的文件夹相同的文件夹中创建输出文件.

It would then use the folderLoc variable and append the output file name to it in order to create the output file in the same folder as where the macro is stored.

Set repFso = CreateObject("Scripting.FileSystemObject")
Set repFile = repFso.CreateTextFile(folderLoc & "RCHT_OPTION4_REPORT.txt", True)

宏存储在 D:\ 驱动器的文件夹中,但是当我运行上面的代码段时,它会获取桌面的位置.

The Macro is stored in a folder in the D:\ drive but when I run the above segment of code it get the location for the desktop.

推荐答案

当前目录(启动进程时所在的位置")和脚本的目录之间存在差异:

There is a difference between the current directory ('where you are when you start the process') and the script's directory:

>> WScript.Echo 0, goFS.GetAbsolutePathName(".\")
>> WScript.Echo 1, goWS.CurrentDirectory
>> WScript.Echo 2, goFS.GetParentFolderName(WScript.ScriptFullName)
>>
0 C:\Documents and Settings\eh
1 C:\Documents and Settings\eh
2 M:\bin

(我从主目录调用了位于 m:\bin 中的 REPL/Interactive VBS shell)

(I called my REPL/Interactive VBS shell that resides in m:\bin from my home directory)

我不知道Cubes_Macro_V5.zmc"是否 VBScript 文件(具有特殊的扩展名,由您通过 w|cscript.exe 使用的任何代理加载),但请检查 WScript.ScriptFullName 具有预期的内容并应用 .GetParentFolderName.

I don't know if "Cubes_Macro_V5.zmc" is a VBScript file (with a special extension that is loaded by whatever agent you use via w|cscript.exe), but check if WScript.ScriptFullName has the expected content and apply .GetParentFolderName.

如果失败,您需要确定您的代理用于宏的文件夹并将该目录提供给 .BuildPath.

If that fails, you need to determine the folder that your agent uses for macros and feed that directory to .BuildPath.

再三考虑:

巫毒但易于测试:是否

WScript.Echo 0, goFS.GetAbsolutePathName(".\Cubes_Macro_V5.zmc")

交付想要的结果?

这篇关于VBScript 宏 getParentFolder 名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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