【发布时间】:2010-03-23 17:11:35
【问题描述】:
我正在使用Shell.Application 对象,它允许我编写 zip 文件的脚本创建。
但为了让它工作,我需要 zip 文件的完整路径。 File.zip 不起作用。我需要c:\the\full\path\file.zip,即使脚本在找到文件的同一目录中运行。
如何获取VBScript中文件的完整路径?
类似于 cmd.exe shell 中的 %~fI 扩展。
【问题讨论】:
我正在使用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
【讨论】: