我正在使用Shell.Application
对象,它允许我脚本化创建一个zip文件。
但是为了使这个工作正常,我需要zip文件的完整路径。File.zip
是不行的。即使在脚本运行的目录中找到该文件,我也需要c:\the\full\path\file.zip
。
如何在VBScript中获取文件的完整路径?
类似于cmd.exe shell中的%~fI
扩展。
在Scripting.FileSystemObject中,有一个叫做GetAbsolutePathName的方法可以实现这个功能。
下面是我成功使用的示例:
Dim folderName
folderName = "..\.."
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim fullpath
fullpath = fso.GetAbsolutePathName(folderName)
WScript.Echo "folder spec: " & folderName
WScript.Echo "fullpath: " & fullpath
Set objFS=CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFile= objArgs(0)
Set objFile = objFS.OpenTextFile(strFile)
Set objFile = objFS.GetFile(strFile)
WScript.Echo objFile.Path
c:\test> cscript //nologo myscript.vbs myfile