如何在VBScript中获取文件的完全限定路径?

Che*_*eso 19 vbscript path

我正在使用该Shell.Application对象,它允许我编写zip文件的脚本.

但为了使其工作,我需要完整的zip文件路径. File.zip不起作用.c:\the\full\path\file.zip即使脚本在找到文件的同一目录中运行,我也需要.

如何在VBScript中获取文件的完整路径?

类似于%~fIcmd.exe shell中的扩展.

Che*_*eso 29

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
Run Code Online (Sandbox Code Playgroud)


gho*_*g74 5

例如

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 
Run Code Online (Sandbox Code Playgroud)

在命令行上

c:\test> cscript //nologo myscript.vbs myfile
Run Code Online (Sandbox Code Playgroud)