Computing Atman
VBS | Getting the current folder.
📁

VBS | Getting the current folder.

Sample source code of a function in VBS to retrieve the path of the current folder

2020/02/24

Here is a sample source code of a function in VBS to retrieve the path of the current folder.

Sample Code

Option Explicit
 
Msgbox GetCurrentDirectory()
 
' ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
' breif : Getting the current folder
' note  :
' ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
Function GetCurrentDirectory()
 
    Dim objWshShell     ' WshShell object
 
    Set objWshShell = WScript.CreateObject("WScript.Shell")
    If Err.Number <> 0 Then
        WScript.Echo "error: " & Err.Description
        wscript.quit(1)
    End If
    GetCurrentDirectory = objWshShell.CurrentDirectory
 
End Function

Explanation

This script retrieves the current folder (also known as the current directory) in which the VBS file (executable file) is located.

Note: The terms "current folder" and "current directory" are used interchangeably.