How to get the fully qualified path for a file in VBScript?

Cheeso picture Cheeso · Jan 25, 2010 · Viewed 88.7k times · Source

I am using the Shell.Application object, which allows me to script creation of a zip file.

But in order for this to work, I need to full path of the zip file. File.zip doesn't work. I need c:\the\full\path\file.zip, even if the script is running within the same directory where the file is found.

How can I get the full path of a file in VBScript?

Something like the %~fI expansion in the cmd.exe shell.

Answer

Cheeso picture Cheeso · Feb 10, 2010

On Scripting.FileSystemObject, there's a method called GetAbsolutePathName that does this.

This is what worked for me:

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