Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 624
Cheeso Avatar asked Jan 24 '10 23:01

Cheeso


People also ask

What is FSO in VBScript?

With the FSO model's File object, you can manipulate files in VBScript applications. The File object represents a file in a Windows file system. After you access the File object, you can use the object's methods and properties to work with it.

What is relative path?

A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy.

What is VB scripting language?

VBScript ("Microsoft Visual Basic Scripting Edition") is an Active Scripting language developed by Microsoft that is modeled on Visual Basic. It allows Microsoft Windows system administrators to generate powerful tools for managing computers with error handling, subroutines, and other advanced programming constructs.


1 Answers

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 
like image 198
Cheeso Avatar answered Oct 24 '22 19:10

Cheeso