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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With