tags:

views:

359

answers:

2

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.

A: 

For example

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 

on command line

c:\test> cscript //nologo myscript.vbs myfile
ghostdog74
A: 

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
Cheeso